2017-08-01 25 views
0

有没有可能在geom_line上添加一种带平均距离绝对值的平滑带?如何用geom_smooth在geom_line上添加平均值的偏差?

我有这样一个矩阵:

    mean  Date   abs(mean-observed_value) 
1     0.2955319 2015-08-04  1.167321e-02 
2     0.2802859 2015-08-12  7.537708e-03 
3     0.2671653 2015-08-20  2.074987e-03 
4     0.2552016 2015-08-28  4.883826e-03 
5     0.2554279 2015-09-05  4.419968e-03 

在ABS(均值observed_value)列有很多时间序列的54个看法各一台,以及日期和平均的喜欢群体,被反复每54行。我正在策划所有的时间序列(使用正确的value,像这样:

p<-ggplot() + 
    geom_line(data = y_m, aes(x = Date, y = value, group = variable), color="steelblue", size =0.1) 
p + geom_line(data =y_mean, aes(x = Date, y = as.numeric(df.ts_mean)), color=1, size =2) + ylab("EVI") 

enter image description here

但是现在有了偏差我要绘制他们为光滑带事情是这样的: enter image description here

我非常欣赏的任何可能的解决方案!非常感谢!

回答

1

您可以使用geom_ribbonggplot2()包在那里你可以建立yminymax值(在你的情况下,这将是ABS列),这里有一个例子代码:

library(ggplot2) 
huron <- data.frame(year = 1875:1972, level = as.vector(LakeHuron)) 
h <- ggplot(huron, aes(year)) 
h + geom_ribbon(aes(ymin = level - 1, ymax = level + 1), fill = "grey70") + 
    geom_line(aes(y = level)) 

请对未来岗位的样本数据为dput()输出,它更容易使用它,而不是复制每个值!

相关问题