-
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
alignment problem with preserve = "single" and preserve = "total" #4350
Comments
Running the reprex: library(tidyverse)
mtcars2 <- bind_rows(mtcars, data.frame(gear = c(4,5), mpg = c(22, 19), am = c(2, 2)))
ggplot(mtcars2, aes(factor(gear), mpg, fill = factor(am))) +
geom_boxplot(position = position_dodge2(0.75, preserve = 'single')) +
geom_point(position = position_dodge(0.75, preserve = 'total')) Created on 2021-02-18 by the reprex package (v1.0.0) Is #2801 related? |
That does seem to be a related issue -- was there a workaround to implement that solution prior to the commit which fixed the issue? |
Is this the same issue as #3647? |
Above PR solves the current bug. But it's not a good solution because future changes in the position selection algorithm in one of the Following script reproduces the same problem as in this issue and #3647: library(tidyverse)
set.seed(42)
df <- bind_rows(lapply(1:7, function(i) {
data.frame(
x = i,
y = rnorm(10*i),
g = sample(LETTERS[seq_len(i)], 10*i, replace = T)
)
}))
ggplot(df, aes(as.factor(x), y, fill = g)) +
geom_boxplot(position = position_dodge2(0.75, preserve = "single")) +
geom_point(position = position_dodge(0.75, preserve = "total"), shape = 4)+
xlab("number of groups") Created on 2022-08-14 by the reprex package (v2.0.1) And the plot generated by the above PR fixes the misalignment problem. |
in your plot, the position of the boxplots has changed from before and the distance between the boxplots depends on the n of groups not sure this will be a desirable visual change |
Yes thanks for spotting this! I'll close this as a duplicate |
This issue is a follow-up on #2712 (comment).
The previously posted solution does not work when there are 3 grouping levels, in which case the geom_point and geom_boxplot layers no longer match up again.
Reprex:
The text was updated successfully, but these errors were encountered: