The recent update to ggplot2 (2.2.0) has broken some of our plots, as the order in which points are drawn has changed. For instance, the following code:
library(dplyr)
library(ggplot2)
library(tibble)
df <- tribble(~a, ~x, ~y,
"I", "A", 2,
"I", "B", 3,
"II","A", 2,
"II","B", 3)
ggplot(df, aes(x = x, y = y, color = a)) +
geom_point(size = 5, position = position_dodge(width = 0.1))+
coord_cartesian(ylim = c(0,15))
produces different versions between the two most recent versions of ggplot2,
Note the difference in the order in which the points are overlapped (i.e. the new version overlaps with the left-most point on top). I can reverse the order in which the categories overlap by reversing the factor order:
library(dplyr)
library(ggplot2)
library(tibble)
library(forcats)
df <- tribble(~a, ~x, ~y,
"I", "A", 2,
"I", "B", 3,
"II","A", 2,
"II","B", 3)
ggplot(df, aes(x = x, y = y, color = fct_rev(a))) +
geom_point(size = 5, position = position_dodge(width = 0.1))+
coord_cartesian(ylim = c(0,15))
but this doesn't help, as it now also reverses the dodging order.
Does anyone know of any way to reproduce the previous behaviour? Is it possible to manually reverse the order in which points are drawn without changing the order in which they are dodged?
It's also not too difficult to build your own position dodge:
Test…