-
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
Additive constant in expand=
behaves unexpectedly on discrete axes in facets with one group
#2281
Comments
The root cause of the problem is |
/move to r-lib/scales |
So this turns out to be kind of a two part problem. The first part, that The fix:With the new PR, the motivating problem is fixed because the range is now calculated to allow for the default library(ggplot2) ### loading scales PR161
library(dplyr)
library(forcats)
iris %>%
mutate(S2 = fct_collapse(Species, "not versicolor" = c("setosa", "virginica"))) %>%
ggplot(aes(Species, Sepal.Length)) +
geom_boxplot(width = 1) +
facet_grid(~S2, scales = "free_x", space = "free_x") and now adjustable: # scales PR161
iris %>%
mutate(S2 = fct_collapse(Species, "not versicolor" = c("setosa", "virginica"))) %>%
ggplot(aes(Species, Sepal.Length)) +
geom_boxplot(width = 1) +
facet_grid(~S2, scales = "free_x", space = "free_x") +
scale_x_discrete(expand = c(0, 2)) The still broken? A new issue...However, I can still create this issue and more! The second part of our two part bug has to do with how the In the original post, # scales PR161
iris %>%
mutate(S2 = fct_collapse(Species, "not versicolor" = c("setosa", "virginica"))) %>%
ggplot(aes(Species, Sepal.Length)) +
geom_boxplot(width = 1.5) +
facet_grid(~S2, scales = "free_x", space = "free_x") But thankfully now the add argument can help mediate this manually. # dev scales PR 161 again
iris %>%
mutate(S2 = fct_collapse(Species, "not versicolor" = c("setosa", "virginica"))) %>%
ggplot(aes(Species, Sepal.Length)) +
geom_boxplot(width = 1.5) +
facet_grid(~S2, scales = "free_x", space = "free_x") +
scale_x_discrete(expand = c(0, 2)) However, looking at both the above plots, you'll notice that the width of the boxplots in the first facet is actually smaller (not larger as specified) and they no longer line up with their ticks. This is not a result of the new PR (I've triple checked) but rather a wholly different bug I've found in how This is especially evident for groups of more boxplots, made with scales 0.5.0 and ggplot2 3.0.0:
Interestingly the behaviour is very erratic depending on |
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/ |
This issue occurs when using a discrete axis on in a faceted plot with free scales and free space, and one of the panels only has a single break on the axis. I would expect that the physical space taken up by each tick is the same (it is), but also that the
expand =
argument would behave independently of the number of ticks on the axis (it does not). This means that the physical space outside the ticks increases for panels with multiple ticks, but it is not changing for panels with only one tick.Here the boxes touch the edges of the panel in the versicolor facet, but there is an expansion gap in the not versicolor facet. This seems to not be expected behavior, since the space for 0.6 of an extra tick should be there in both panels.
If you try to increase the additive constant to add an expansion gap in the versicolor facet, no gap is created:
Space for a full discrete break was added on each side of the not versicolor facet, but no space was added to the sides of the versicolor facet, so the edges of the box still touch the edge of the panel.
The text was updated successfully, but these errors were encountered: