【发布时间】:2015-05-28 15:29:29
【问题描述】:
我正在尝试使用 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?
【问题讨论】: