infotroph / ggplotTicks

Copy axes from bottom to top and left to right sides of a ggplot.
Other
9 stars 1 forks source link

Changing facets loses mirroring #4

Open infotroph opened 8 years ago

infotroph commented 8 years ago

As currently implemented, mirror_ticks(p) works by subclassing p$facet, but meanwhile the current implementation of ggplot's + operator handles p + facet_* by overwriting p$facet entirely. This means refaceting a previously-mirrored plot will produce an unmirrored plot.

Current workarounds: Adopt a style where you call mirror_ticks last thing before plotting, or else wrap additional mirror_ticks calls around any downstream facet changes:

p = mirror_ticks(ggplot(...) + ... )
p = p + ...
...
 p = mirror_ticks(p+facet_wrap(...))

Possible more complete fixes:

infotroph commented 8 years ago

The subclassing option might be easier than I thought. The following is sufficient to obtain a mirrored facet_wrap from a previously unmirrored plot:

facet_tickwrap = function(...){
    f=facet_wrap(...)
    class(f)=c("ggTicks", class(f))
    f
}
p + facet_tickwrap(~fac)

Need to account for all the corner cases of allPanels and of null vs wrap vs grid facets, but those all seem doable.