Open infotroph opened 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.
As currently implemented,
mirror_ticks(p)
works by subclassingp$facet
, but meanwhile the current implementation of ggplot's+
operator handlesp + facet_*
by overwritingp$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 additionalmirror_ticks
calls around any downstream facet changes:Possible more complete fixes:
+
with a version that adds mirroring back on after rewriting a facet?Subclass the facet_* functions? Major API change, but might allow a nicely gg-ish interface:
Would be easier if/when ggplot facets are rewritten with extensibility in mind; unofficial word from Hadley (via Twitter 2016-02-02) is that changing facets to ggproto is on his "eventually" list.