我有这个情节,我首先使用geom_line
使用color:variable
调整融合的表格,为不同的线条着色。
然后我尝试拟合第二个元素,即geom_ribbon
。然后我收到错误消息:
eval(expr,envir,enclos)出错:找不到对象'变量'
为什么?我没有在第二个元素中使用它。一个次优的解决方法是在功能区geom中用color = NA覆盖,但是这会在我的功能区周围产生一条我不想要的黑线。
ggplot(data, aes(x=as.Date(date), y=value, group=variable, color=variable)) +
geom_line() +
geom_ribbon(data=fitted, aes(x=as.Date(date), y=forecast, ymin=lower, ymax=upper, fill="black", group=1), alpha=.2, fill="red")
答案 0 :(得分:2)
如果您在color=variable
aes()
来电ggplot()
中设置了geom_ribbon()
,那么variable
也会尝试使用inherit.aes=FALSE
作为颜色。在geom_ribbon()
内添加{{1}}以确保不使用先前设置的美学。