Smarter (more generous) padding for categorical axes with few levels - #732
Merged
Merged
Conversation
Owner
Author
|
@zeileis @vincentarelbundock I know that you're both busy, but I'd appreciate a quick thumbs up if you're supportive of the basic idea. (No need to look at the code.) |
- also avoid duplicate xpad_user capture
Collaborator
|
Thanks, I think this looks better! |
Owner
Author
|
Thanks Vincent! I think so too, so taking a majority vote ;-) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow up to #729
The default padding at the end of categorical axes has bothered me for a while. Specifically, our plots don't look great when a categorical axis contains few levels (categories), since the outer plot elements are pressed flush against the axis limits, whilst leaving a lot of dead space in between.
At the same time, this isn't really an issue for plot types with "wider" glyphs (e.g., boxplots, violin, or jittered points). These generally look fine under the current defaults, even with few categories Sometimes this is b/c they ship their own spacing (
type = "boxplot"does this, for example) and other times it's just because the wider glyph area naturally helps to balance the plot (jittered point do this, for example).I've wanted to implement a more balanced default, which improves the overall plot aesthetic by being responsive to underlying plot type (glpyh) and overall spacing requirements (number of categories).
This PR builds on the new
x/ypadmachinery (#729), by implementing more generous end padding for categorical axis types when:"p","pointrange", etc.If both (1) and (2) true, then axis padding is set to to 25% of the gap between the interior tick intervals. In other words, the outer ticks get a quarter of the regular spacing from edges of the plot frame.
If either (1) or (2) is not true, then the padding reverts back to its normal behaviour, i.e, 4% expansion in most cases; larger for "wide" glyphs like boxplots.
MWE
The end result is easier to visualize than explain, so see the comparison of Current vs Proposed outcomes for the
"p"and"pointrange"types below.Again, I emphasize is that this expanded padding doesn't kick in all the time. Below I show some types where the end result is identical for the Current and Proposed branches b/c of the "smart" overrides (e.g., when a large number of categorical groups is detected, as in the bottom row).