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
geom_boxplot + width != 1 moves boxes #2331
Comments
I should mention, adding position = position_dodge2(preserve = "total") as described in #2290 eliminated my need to widen up the box plots (I'm doing a bunch of facet boxplots)...but this behavior still seems strange to me. |
Reprex with simpler data, although it needs a bigger width before the problem becomes apparent: library(ggplot2)
df <- data.frame(
x = rep(c("a", "b"), each = 3),
y = c(1, 2, 3, 5, 6, 7)
)
ggplot(df, aes(x, y)) +
geom_boxplot(width = 1) +
geom_vline(xintercept = c(0.5, 1, 1.5, 2, 2.5), alpha = 1/4)
ggplot(df, aes(x, y)) +
geom_boxplot(width = 2) +
geom_vline(xintercept = c(0.5, 1, 1.5, 2, 2.5), alpha = 1/4) ggplot(df, aes(x, y)) +
geom_boxplot(width = 3) +
geom_vline(xintercept = c(0.5, 1, 1.5, 2, 2.5), alpha = 1/4) I bet this is because boxplots now are wide enough that they overlap, and hence the new dodging algorithm combines into a single group. @karawoo maybe this is correct behaviour and not actually a bug? |
Lines 83 to 86 in 0648739
In the third width is 3 and number of elements is 2, so after this calculation the width is still greater than 1, whereas in the second it's exactly 1. I think
tl;dr I think the current behavior is correct. But maybe we should document somewhere that width should not be greater than 1? |
I agree - I think this is correct behaviour. I'm not sure how we should document since width could be greater than one if the boxplots are spread further apart (i.e. numeric x rather than categorical x). So I think we're ok here. |
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/ |
(possibly related to #2290)
I'd like to make the width of the boxplots a bit fatter, but when I do that, the labels no longer align with the boxplot:
I would have guessed the width of the boxplot gets bigger, but the position would stay the same.
The text was updated successfully, but these errors were encountered: