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)