如何在R中的qplot上添加SD

时间:2014-03-06 21:38:48

标签: r ggplot2 standard-deviation

我的数据:

Store;

founder wt.Df   Viability   avg_val sd
1   A3  D   0   0   0
2   A3  D   0   0   0
3   A3  D   0   0   0
4   A3  D   0   0   0
5   A3  W   0.5 0.5 0.0673435
6   A3  W   0.5 0.5 0.0673435
7   A4  D   0.4 0.4 0.01594978
8   A4  D   0.4 0.4 0.01594978
9   A4  D   0.3 0.3 0.06475337
10  A4  D   0.3 0.3 0.06475337
11  A4  W   0.5 0.5 0.04831164
12  A4  W   0.5 0.5 0.04831164

qplot(x=wt.Df, y=avg_val, group=founder, data=Store1, geom="line", colour = factor(founder), main= "LOVE CODE, xlab = "Lines", ylab = "Average Viability", ylim=c(0,1), xlim= (c("W", "D"))) + geom_point() + labs(colour="Founders Tested") + opts(axis.text.x = theme_text(angle=10));

我想做什么,我在网上找不到任何东西;因此,我在问。我怎么能拿Store $ Sd并将它们绘制到我的qplot图上的点?我想要上面带有错误条的情节?

1 个答案:

答案 0 :(得分:1)

此?

library(ggplot2)
qplot(x=wt.Df, y=avg_val, group=founder, data=Store1, geom="line", 
      colour = factor(founder), 
      main= "LOVE CODE", xlab = "Lines", ylab = "Average Viability", 
      ylim=c(0,1), xlim= (c("W", "D"))) + 
  geom_point() + 
  labs(colour="Founders Tested") + 
  theme(axis.text.x = element_text(angle=10))+
  geom_errorbar(aes(x=wt.Df, ymin=avg_val-sd, ymax=avg_val+sd), width=.1)

我不确定你为什么要使用线条 - 它似乎只会造成混乱。