I would like to make a point range plot where points of groups are not stacked on each other. The plot should look like this::
My best attempt to do the dodging is to use a vector in dodge argument:
library(ggplot2)
dat <- structure(list(Treatment = structure(c(1L, 1L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 2L, 2L, 2L), .Label = c("A", "B"), class = "factor"),
Temp = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L,
2L, 2L), .Label = c("10", "20"), class = "factor"), Rep = c(1L,
2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L), Meas = c(3L,
2L, 2L, 2L, 6L, 4L, 4L, 3L, 5L, 1L, 2L, 3L), SD = c(2L, 3L,
2L, 2L, 2L, 3L, 2L, 3L, 3L, 3L, 2L, 1L)), .Names = c("Treatment",
"Temp", "Rep", "Meas", "SD"), row.names = c(NA, -12L), class = "data.frame")
ggplot(dat, aes(x = Treatment, y = Meas, ymin = Meas - SD/2, ymax = Meas + SD/2)) +
geom_linerange(aes(color = Temp), position=position_dodge(width=c(0.6,0.4)), size = 1, alpha = 0.5) +
geom_point(aes(color = Temp, shape = Temp), position=position_dodge(width=c(0.6,0.4)), size = 3) +
theme_bw()
Which leads to a plot shown below. However, all of the points are not dodged and I have to move the dots and error bars in Illustrator to get a plot show above. Is there a way to use dodge argument in ggplot2
on two levels?