[英]Create geom_ribbon for min-max range
Given the following data: 鉴于以下数据:
df<-data.frame(
year=(1996:2000),
a=c(2,1.5,1.5,2,3),
b=c(2,2,2,3,4),
c=c(2,3,3,1,1))
with ggplot: 与ggplot:
ggplot(df,aes(x=year))+
geom_line(aes(y=a))+
geom_line(aes(y=b))+
geom_line(aes(y=c))
looking like this: 看起来像这样:
how. 怎么样。 can I create a ribbon that shows always the area between minimum and maximum (think of it like a min-max-range), to get it look like this:
我可以创建一个功能区,始终显示最小值和最大值之间的区域(将其视为最小 - 最大范围),使其看起来像这样:
What about first computing the mininum and maximum values: 首先计算最小值和最大值怎么样:
df$min <- apply(df[, -1], 1, min)
df$max <- apply(df[, -1], 1, max)
And then simply plotting the ribbon: 然后简单地绘制色带:
ggplot(df, aes(x = year, ymin = min, ymax = max)) + geom_ribbon()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.