我正在尝试使用 ggplot 绘制数据框,该数据框看起来像http://www.ats.ucla.edu/stat/r/dae/logit.htm底部的图。
       a<-data.frame(Year=c("2012","2012","2012","2013","2013","2013","2014","2014","2014"),
          Engagement=rep(c("low","med","high"),3),
         cost=c(4464.88,4690.14,4342.72,5326.63,5000.03,3967.02,4646.27,4282.38,3607.79),
         lower=c(4151.4,5027.51,4095.73,4366.82,4682.85,3715.86,3775.25,3642.41,3235.43),
         upper=c(4778.35,5625.75,5196.81,5013.45,5317.2,4848.89,4910.19,4291.64,3980.14))
我试过:
k<-ggplot(a,aes(x=Year,y=cost))
k+geom_ribbon(aes(ymin=lower,ymax=upper,fill=Engagement),alpha=0.2)+
geom_pointrange(aes(x=Year,y=cost,ymin=lower,ymax=lower),size=1,width=0.2,color="blue")
我感谢所有的帮助。
我刚刚也尝试过:
pd <- position_dodge(0.1)
k<-ggplot(a,aes(x=Year,y=cost))
k+geom_ribbon(aes(ymin=lower,ymax=upper,fill=Engagement),alpha=0.2)+
  geom_line(position=pd,aes(color=Engagement))
错误信息:
ymax not defined: adjusting position using y instead
geom_path: Each group consist of only one observation. 
Do you need to adjust the group aesthetic?
谢谢大家,问题解决了:
k+geom_line(aes(group=Engagement,color=Engagement))+
  geom_errorbar(aes(ymin=lower,ymax=upper,color=Engagement,width=0.2))

| 归档时间: | 
 | 
| 查看次数: | 9275 次 | 
| 最近记录: |