geom_ribbon doesn't work - Error in eval(expr, envir, enclos) : object 'variable' not found

不打扰是莪最后的温柔 提交于 2019-12-04 06:55:41

You got this error because variable is used for color in aes() of function ggplot(). When you add geom_ribbon() with new data frame geom_ribbon() tries to find variable in new data frame to use it for colors. To ignore this variable add inherit.aes=FALSE inside geom_ribbon() - so you are telling that all parameters should be taken independently - that's way you should set x=xaxis again in geom_ribbon().

ggplot(dfm, aes(x = xaxis, y = value, colour = variable)) + 
  geom_line(aes(group=variable)) + 
  geom_ribbon(data=df, aes(group = 1, x = xaxis,ymin=output1, ymax=output2),
                       inherit.aes=FALSE)

The definition for color = variable is being carried over from the original ggplot layer. Override it in the call to geom_ribbon to make it work: geom_ribbon(data = df, aes(group = 1, ymin=output1, ymax=output2, color=I('red')).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!