Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing facets loses mirroring #4

Open
infotroph opened this issue Feb 16, 2016 · 1 comment
Open

Changing facets loses mirroring #4

infotroph opened this issue Feb 16, 2016 · 1 comment

Comments

@infotroph
Copy link
Owner

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:

  • Mask + 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:

    p + facet_wrap_ticks(~fac, sides="trbl")
    p + facet_grid_ticks(f1~f2, scales="free_y", sides="lr", allPanels=TRUE)
    p + facet_null_ticks() #...might want a better name for the one-panel case, tho
    

    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.

@infotroph
Copy link
Owner Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant