在ggplot中躲避

时间:2014-02-12 18:13:49

标签: r ggplot2

使用此数据

Data <- structure(list(StudyArea = c("AAA", "BBB", "CCC", "AAA", "BBB", 
"CCC", "AAA", "BBB", "CCC"), Obs = c(190L, 481L, 219L, 190L, 
481L, 219L, 190L, 481L, 219L), InSituPred = c(180, 462, 199, 
180, 462, 199, 180, 462, 199), InSituSE = c(9.57382456553708, 
16.5306359391421, 9.51070020039693, 9.57382456553708, 16.5306359391421, 
9.51070020039693, 9.57382456553708, 16.5306359391421, 9.51070020039693
), variable = c("ExSituAAA", "ExSituAAA", "ExSituAAA", "ExSituBBB", 
"ExSituBBB", "ExSituBBB", "ExSituCCC", "ExSituCCC", "ExSituCCC"
), value = c(NA, 500, 172, 156, NA, 161, 200, 562, NA), SE = c(20.8552264204181, 
16.1382421185167, 21.43693858142, 20.8552264204181, 16.1382421185167, 
21.43693858142, 20.8552264204181, 16.1382421185167, 21.43693858142
)), .Names = c("StudyArea", "Obs", "InSituPred", "InSituSE", 
"variable", "value", "SE"), row.names = c(NA, -9L), class = "data.frame")

看起来像这样

StudyArea Obs InSituPred  InSituSE  variable value       SE id
1       AAA 190        180  9.573825 ExSituAAA    NA 20.85523  1
2       BBB 481        462 16.530636 ExSituAAA   500 16.13824  2
3       CCC 219        199  9.510700 ExSituAAA   172 21.43694  3
4       AAA 190        180  9.573825 ExSituBBB   156 20.85523  1
5       BBB 481        462 16.530636 ExSituBBB    NA 16.13824  2
6       CCC 219        199  9.510700 ExSituBBB   161 21.43694  3

和此代码

dodge <- position_dodge(width = 0.4)
p <- ggplot(Data, aes(x=StudyArea))+
  geom_point(aes(y=value, color=variable),size=3, shape=1,position=dodge)+
  geom_errorbar(aes(ymin=value-SE, ymax=value+SE, color=variable),position=dodge, lty = 2, cex=0.75)+
  geom_point(aes(y=InSituPred, color=StudyArea),size=3, shape=1)+
  geom_errorbar(aes(ymin=InSituPred-InSituSE, ymax=InSituPred+InSituSE, color=StudyArea ), lty=1,cex=0.75)+
  geom_point(aes(y=Obs, color=StudyArea),shape="*",size=12)

p +  scale_color_manual(name="Study Area \nPrediction", 
                        values=c("red", "blue", "darkgreen","red","blue","darkgreen"), 
                        breaks=c("ExSituAAA", "ExSituBBB", "ExSituCCC"))

我可以创建这个情节 fig

我希望dodge实线两侧的虚线,就像当前在StudyArea BBB中完成的那样。根据{{​​3}}提供的有用评论,我尝试为variable列中的每个值添加唯一列,但dodge - ing不会更改。

有关如何使StudyArea AAA和CCC看起来像BBB(即居中的实线和左右虚线)的建议将不胜感激。

感谢。

0 个答案:

没有答案