我想制作一个点范围图,其中组的点不相互堆叠。情节应如下所示:
我最好的躲避尝试是在躲避参数中使用向量:
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()
这导致如下图所示。然而,所有的点都没有被躲开,我必须在 Illustrator 中移动点和误差线才能得到上面的绘图。有没有办法ggplot2
在两个层面上使用闪避参数?