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

reverse dodge order works differently in position_jitterdodge() vs., for example position_dodge2() #3610

Open
davebraze opened this issue Nov 4, 2019 · 3 comments
Labels
feature a feature request or enhancement positions 🥇

Comments

@davebraze
Copy link

Reversing the order of dodged elements using position_dodge2(), one passes in reverse=TRUE. To reverse dodged element positions in position_jitterdodge(), it is necessary to use a negative value to dodge.width=-.75; there is no 'reverse' argument. This is undocumented in position_jitterdodge and inconsistent with other dodge functions.

@clauswilke
Copy link
Member

Please provide a reprex.

@smouksassi
Copy link

davebraze is asking why there is no reverse argument for jitterdodge or at least document negative width behavior

library(ggplot2)
ggplot(mtcars,aes(as.factor(cyl),mpg,fill=as.factor(vs),color=as.factor(vs)  ))+
  geom_boxplot(position = position_dodge2(reverse = TRUE),color="black")+
  geom_point(position =position_jitterdodge(dodge.width = -0.75))
#> Warning: position_jitterdodge requires non-overlapping x intervals

Created on 2019-11-07 by the reprex package (v0.3.0)

@thomasp85 thomasp85 added feature a feature request or enhancement positions 🥇 labels Jan 21, 2020
@joelgautschi
Copy link

joelgautschi commented Jan 26, 2021

the same is true for position_dodge() with geom_point(): position_dodge(width = -0.5) gives a warning. However, the order is reversed as I had hoped.

library(tidyverse)

df <- tribble(~dimension, ~group, ~value,
              "dim 1", "A", 0.6,
              "dim 1", "B", 0.75,
              "dim 1", "C", 0.25,
              "dim 2", "A", 0.4,
              "dim 2", "B", 0.4,
              "dim 2", "C", 0.5)

plot <- ggplot(data = df,
               mapping = aes(x = dimension,
                             y = value,
                             color = group)) 

# warning
plot +  
  geom_point(position = position_dodge(width = -0.5))
#> Warning: position_dodge requires non-overlapping x intervals

Created on 2021-01-26 by the reprex package (v0.3.0)

The question remains whether this is 'good practice' or if it is better to use an approach like color = fct_rev(group) within aes() to reverse the order.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement positions 🥇
Projects
None yet
Development

No branches or pull requests

5 participants