Use ggplot2 to plot two lines with ribbons
I have a data frame with metric v and a categorical variable t. I can plot them as lines like this
set.seed(42)
v <- runif(20, min=0, max=100)
t <- sample( LETTERS[1:2], 20, replace=TRUE )
df <- data.frame(v,t)
qplot(1:length(v),v,data=df,geom="line",group=t,color=t)
I would like to add ribbons around each line. Possibly different widths (which I will set with the formula) and opacity. I tried to replace geom with "feed", but I got the following error:
qplot(1:length(v),v,data=df,geom="ribbon",group=t,color=t)
Error: geom_ribbon requires the following missing aesthetics: ymin, ymax
How can I plot both rows and their ribbons in one chart?
+3
source to share