-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Stacked axes #5473
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
Stacked axes #5473
Conversation
), i = "Guides need to handle {.field x} and {.field y} aesthetics.")) | ||
} | ||
|
||
params <- lapply(axes, `[[`, name = "params") |
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.
Keep track of #5474
This comment was marked as resolved.
This comment was marked as resolved.
Merge branch 'main' into stacked_axis # Conflicts: # DESCRIPTION # NAMESPACE # _pkgdown.yml # man/ggplot2-ggproto.Rd # tests/testthat/test-guides.R
Now also compatible with devtools::load_all("~/packages/ggplot2")
#> ℹ Loading ggplot2
p <- ggplot(mtcars, aes(hp, disp)) +
geom_point() +
coord_radial(start = 0.25 * pi, end = 1.75 * pi, donut = 0.5) +
guides(
theta = guide_axis_stack("axis_theta", guide_axis_theta(cap = "both")),
theta.sec = guide_axis_stack("axis_theta", guide_axis_theta(cap = "both")),
r = guide_axis_stack("axis", guide_axis(cap = "both")),
r.sec = guide_axis_stack("axis", guide_axis(cap = "both"))
) +
theme(axis.line = element_line())
p Where the stacked ring appears depends on the size of the labels. It may go outside the bounding box of the panel and start to overlap with axis titles. I don't think there is a good solution for this, as the dimensions of the ring depend both on the panel size in relative units and the size of the axis in absolute units. However, people can always adjust margins manually if they insist. p + scale_x_continuous(
breaks = c(100, 200, 300),
labels = rep("long label", 3)
) Created on 2023-11-24 with reprex v2.0.2 Also some weirdness may occur if the donut hole is too small to fit all devtools::load_all("~/packages/ggplot2")
#> ℹ Loading ggplot2
p <- ggplot(mtcars, aes(hp, disp)) +
geom_point() +
coord_radial(start = 0.25 * pi, end = 1.75 * pi, donut = 0.1) +
guides(
theta.sec = guide_axis_stack("axis_theta", "axis_theta", "axis_theta")
) +
theme(axis.line = element_line())
p Created on 2023-11-24 with reprex v2.0.2 |
Should we add a way to individually control the theme of every axis in the stack? |
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.
It's a bit annoying that the radial axis needs to have so much extra logic for the off-chance that it is stacked, but I see no way around it. And at least it is not mingled in with all the other code
Yeah it is a shame that it is so non-trivial to calculate the width of the ring. |
Merge branch 'main' into stacked_axis # Conflicts: # man/ggplot2-ggproto.Rd
This PR is a proof-of-concept for an axis guide that stacks other axis guides.
For context: I don't really think stacked axes are all too useful for data visualisation except maybe to display two different units of the same measurement on an axis (degree celsius/fahrenheit, metres/inches etc.). Certainly in its current form, this PR cannot even do that (but that might be amended by #5410). Arguably, that functionality shouldn't live in ggplot2 but in extension packages.
However, the display of multiple units is not the goal of this axis guide. The goal of this axis guide is to incorporate flexibility in axis composition into ggplot2 itself. That way, the following should be possible:
To give a more concrete example for this, one could view the guide displayed here as a regular axis + annotation for ranges.
Here is some nightmare fuel to show that it works:
Created on 2023-10-11 with reprex v2.0.2