-
Notifications
You must be signed in to change notification settings - Fork 2k
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
scale
option that preserves scale but not location
#5377
Comments
If you pre-calculate the maximum range per facet, you can just use a function as the library(tidyverse)
df <- iris |>
group_by(Sepal.Width) |>
summarize(across(ends_with('Length'), mean)) |>
pivot_longer(ends_with('Length'))
max_range <- df |>
group_by(name) |>
summarise(range = diff(range(value))) |>
summarise(range = max(range)) |>
pull()
ggplot(df, aes(Sepal.Width, value, color=name)) +
geom_line() +
facet_wrap(~name, scales = "free_y") +
scale_y_continuous(
limits = \(x) mean(x) + c(-0.5, 0.5) * max_range
) Created on 2023-08-02 with reprex v2.0.2 |
Oh! I had no idea |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When facetting over things with different range, I currently have the option to give all facets the same axis limits, like so:
or to free axes completely, like so:
free_*
really does two things there though: It frees the scale of the axis – the pixel distance between the breaks – and it frees the absolute location of the scale – whether the break at5
happens at the same horizontal point across facets.I would love to have an option to
scales
that allows me to free location while maintaining scale. That is, vertical distances within each facet would correspond to the same absolute differences in the variable being plotted, but those differences might occur from another baseline.An admittedly very hacky demonstration:
The text was updated successfully, but these errors were encountered: