-
Notifications
You must be signed in to change notification settings - Fork 2.1k
small update to position-dodge2.r #2481
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
Conversation
Hmm, I realise reading the logs for the failed checks that my suggested update breaks functionality as defined in test-position-dodge2.r (it gives a different result for geom_col() and geom_rect() when there is x-overlap, but no grouping).
|
I don't think the travis-ci check broke because of my change, it passes all your tests scripts @karawoo, what do you think? |
Thanks for looking into this @frostell. When I try your update I still get misaligned points and boxes on the left, does this match what you see? # using example from #2480
set.seed(5820)
dat <- data.frame("value" = rnorm(n=30, mean=2, sd=0.5),
"group" = LETTERS[1:3],
"x" = factor(1:2))
dat$value[dat$group=="A"&dat$x=="1"] <- NA
ggplot(dat, aes(x=x, y=value)) +
geom_boxplot(aes(fill=group), alpha=0.3) +
geom_point(aes(colour=group), position=position_dodge2(width=0.75), size=3, alpha=0.5)
#> Warning: Removed 5 rows containing non-finite values (stat_boxplot).
#> Warning: Removed 5 rows containing missing values (geom_point). |
Hello @karawoo! Which version of ggplot are you using? I have 2.2.1.9000 installed, maybe that's the problem? I think you will get the correct alignment if you write: ggplot(dat, aes(x=x, y=value)) +
geom_boxplot(aes(fill=group), position="dodge2", alpha=0.3) +
geom_point(aes(colour=group), position=position_dodge2(width=0.75), size=3, alpha=0.5) Does that work for you? The other possibility is that the default preserve argument differs, then you could try: ggplot(dat, aes(x=x, y=value)) +
geom_boxplot(aes(fill=group), position=position_dodge2(width=0.75, preserve = "single"), alpha=0.3) +
geom_point(aes(colour=group), position=position_dodge2(width=0.75, preserve = "single"), size=3, alpha=0.5) (or "total" instead of "single") |
Ah I see what's happened. I applied your changes onto the current master branch. |
Can you start by describing the key problem with the existing algorithm and how your code fixes it? The current logic is not obvious to me. |
With this small update pos.dodge2() works with geom_point too and it's possible to align boxplots and points even in trickier cases when some unique combinations are all NA's. Background: Problem: Solution: |
Your logic doesn't seem quite general enough to me. I'll take a stab at it myself. |
ok, I admit it was patchy even though it worked for the specific problem :) I guess ideally there would be just one position_dodge function to handle all geoms and stats with appropriate options to choose styling of the "dodging"... Looking forward to see your solution! |
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/ |
Small update to position-dodge2.r to enable alignment of geom_boxplot() and geom_point() with NA's through position_dodge2(), possible patch for #2480.