Skip to content
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

Aligning geoms with preserve = "single": appears not to work with several factors #3647

Closed
adrowe1 opened this issue Nov 29, 2019 · 4 comments · Fixed by #6000
Closed

Aligning geoms with preserve = "single": appears not to work with several factors #3647

adrowe1 opened this issue Nov 29, 2019 · 4 comments · Fixed by #6000
Labels
bug an unexpected problem or unintended behavior positions 🥇

Comments

@adrowe1
Copy link

adrowe1 commented Nov 29, 2019

Hi,

I discovered issue #2712 when looking for a solution to the misalignment of boxplots with overlaid points. While the solution shown works in the example, it does not seem to generalise to cases with a greater number of factors.

Ideally it would be possible to achieve the same thing with position_jitterdodge(), but I guess that is beyond the scope of this issue.

library(ggplot2)

ggplot(mtcars, aes(factor(am), mpg, fill = factor(carb))) + 
  geom_boxplot(position = position_dodge2(0.75, preserve = 'single')) +
  geom_point(position = position_dodge(0.75, preserve = 'total'))

image

@thomasp85 thomasp85 added bug an unexpected problem or unintended behavior positions 🥇 labels Jan 21, 2020
@thomasp85 thomasp85 added this to the ggplot2 3.3.4 milestone Mar 25, 2021
@thomasp85
Copy link
Member

@karawoo do you have any insight here?

@karawoo
Copy link
Member

karawoo commented Apr 20, 2021

I think there are a couple of issues here that are recurring themes with dodging. One is that position_dodge2() doesn't work for point geoms at all, so every time you combine a box plot with points you have to combine completely different dodging algorithms, which is predictably error prone. The other is that layers don't know about the position of elements in other layers, so it's generally hard to align geoms across layers. It's been suggested in the past that maybe the solution would be a dodging aesthetic (this has come up in #3022 and #3988). Unfortunately I don't think there is an easy solution without a major refactor.

@thomasp85
Copy link
Member

So, in your head this is not something we can aim to solve surgically (i.e. without a huge rewrite)..?

@karawoo
Copy link
Member

karawoo commented Apr 21, 2021

Yeah I think that's right, unfortunately

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior positions 🥇
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants