-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Minor ticks #5287
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
Minor ticks #5287
Conversation
I would very much suggest we move all these visual settings to the theming. It is where they belong even if the arguments feel a bit much. We are kinda stuck with theming being applicable from both the guide constructor and theme with some of the old guides but there is no reason to repeat old mistakes :-) |
Yeah I can see why they should live in the theme. The only problem I could foresee is that at the time the information is taken from the scale (in Edit: Another drawback of always extracting minor positions, is that the axis capping from #5289 will snap to minor positions even if the minor ticks aren't drawn. |
Merge branch 'main' into minor_ticks # Conflicts: # R/guide-axis.R # man/guide_axis.Rd # tests/testthat/test-guides.R
This comment was marked as resolved.
This comment was marked as resolved.
Merge branch 'main' into minor_ticks # Conflicts: # R/guide-axis.R
The minor ticks currently need to be set Couple thoughts:
|
Did you ever look into the performance implications of always extracting minor tick positions? I have a feeling it is neigh zero... Also, should we look into #3951 before merging this? |
Currently, extracting minor positions too is about 2x as expensive as just major positions: it goes from ~1ms to ~2ms for guide training.
Yeah let's try |
Merge branch 'main' into minor_ticks # Conflicts: # R/theme-elements.R
I was surprised to learn that apparently ggplot2's theme system works perfectly fine when a In any case, now the leaf Small demo devtools::load_all("~/packages/ggplot2")
#> ℹ Loading ggplot2
minor_axis <- guide_axis(minor.ticks = TRUE)
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
guides(x = minor_axis, x.sec = minor_axis,
y = minor_axis, y.sec = minor_axis) +
theme(
axis.ticks.length = unit(1, "cm"),
axis.ticks.length.y = rel(0.5),
axis.minor.ticks.length = rel(0.5),
axis.minor.ticks.length.x.top = unit(1, "cm"),
axis.minor.ticks.length.y.right = rel(4)
) Created on 2023-09-12 with reprex v2.0.2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This PR aims to fix #4387.
Briefly, it adds 3 arguments to
guide_axis()
:minor.ticks
which takes anelement_{line/blank}
orTRUE/FALSE
to draw minor ticks or not.minor.length
to control the length of the minor ticks, relative to the theme setting.major.length
to control the length of the major ticks, relative to the theme setting.Less briefly:
I wasn't particularly keen to add the whole parade of
axis.ticks.minor.x.top
andaxis.ticks.length.minor.x.top
etc. theme settings for the minor axes. Mostly because I was being lazy, but also the theme arguments are busy enough as it is. The current options provide the same flexibility though.I found out that the axis ticks were anchored incorrectly, which you of course don't see if you have one tick size. As a result of fixing this, the x/y xend/yend order in the colourbar/bin guides' ticks are swapped, which is the cause of all the changes in the visual tests (the alternative was to do this in the axis, which would affect every plot). Note that this affects the svgs, but not what is drawn to screen.
Here is a bit of a contrived example to show the minor ticks, and that they could also work for (fake) discrete axes, if only they had
get_breaks_minor()
implementations. Turning the major ticks off gives the discrete labels nice 'fences' between their areas on the plot.Created on 2023-04-26 with reprex v2.0.2