-
Notifications
You must be signed in to change notification settings - Fork 8
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
Legend and facet spacing #94
Conversation
- Need to set par(mar) margins first. - Also consolidate outer right and left code logic. - Clean up too.
- Principled gaps between facets - Overall plot region matched to single (no facet) plot
- Better internal comments too.
- Also add fmar to par2 options
- Reinstate after this PR is finished
- Specifically 2 by x cases
@vincentarelbundock @zeileis I plan to merge this PR later today. I've stressed tested it a ton and I'm confident that I've caught all of the major edge cases. If either of you have time, however, I'd be grateful for feedback on my default choices of |
Oooh, this looks suuper nice! I don't have anything to say about the spacing. Looks about right to me. I really like this a lot. Feels like with |
💯 |
Indeed. Thank you both!! |
This is a major PR—albeit with few changes on the UI side—that provides a principled approach for fixing the margin spacing for both legends and facets. Specifically:
lmar = c(inner, outer)
parameter, with default values ofc(1.0, 0.1
). The first number represents the "inner" margin in lines between the legend and the plot region. The second number represents the "outer" margin in lines between the legend and the edge of the graphics device. (For "top!" legends, the outer margin represents the extra gap between the legend and the title, since the legend sits underneath the title.)fmar = c(b,l,t,r)
parameter, where the default values arec(1,1,1,1)
. In other words, each individual facet has a single line's worth of space around each of its sides. For faceted plots where"frame.plot = FALSE"
, these gaps are slightly reduced (by 0.5 lines) to reduce the excess whitespace that arises from the missing axes lines and labels.Both
lmar
andfmar
can be can accessed and controlled as part of thepar2()
global parameters.Final thoughts before some examples: This PR took me significantly longer than expected and I ended up squashing quite a few additional hidden bugs during the process. Less pleasantly, I had to grapple with some idiosyncrasies of the base graphics internals that I had so far managed to avoid (example). But having come through the other end, I'm pretty chuffed with the end result. It's big improvement over the existing system, which was very ad hoc even if the "usual" cases looked okay. (Non-standard cases would not look okay.)
Legend margin (
lmar
)Long (and multi-line) legend titles are fine too...
And here's an adjusted
lmar
example.Facet margins (
fmar
)Note that non framed plots get an automatic
fmar
reduction (-0.5 lines) to reduce excess whitespace arising from the missing axes lines and labels.And here is an adjusted fmar example or two.
Side note: We can also set fmar temporarily via facet.args.
Created on 2024-01-20 with reprex v2.0.2