查找并绘制变量均值

时间:2019-04-06 16:27:10

标签: r plot mean

我目前在一条绘图上绘制了5条线(每条线代表一个模型),如下所示:

plot(get,Hope2, type = "l",col = "green", lwd = "3", xlab="Cumulative CO2 
emissions (TtC)", ylab="One-day maximum precipitation (mm/day)", 
main="One-day maximum precipitation for Random Location for CanESM2 
scenarios")
lines(IPSL, Hope6, type = "l", lwd = "3", col = "green")
lines(MIROC, Hope7, type = "l", lwd = "3", col = "green")
lines(subsetprime, Hope8, type = "l", lwd = "3", col = "green")
lines(MPI, Hope9, type = "l", lwd = "3", col = "green")

因此,如您所见,我有5条绿线。我想做的是找到每个元素的平均值/平均值,然后绘制该新线。像这张图片中的中心黑线,蓝线或红线一样:

https://www.mathworks.com/matlabcentral/mlc-downloads/downloads/submissions/47950/versions/4/screenshot.jpg

上面说“希望”的所有内容都是针对y轴变量,而为每行列出的第一个变量均针对x轴。有什么方法可以计算这5个x和y变量的均值并将其绘制为一条新线吗?我想具体平均每个元素之间的140个元素。例如,x变量(即“ get”,“ IPSL”,“ MIROC”,“ subsetprime”,“ MPI”)包含140个元素,因此最终,我想对所有元素1s取平均值,然后对元素2s,所有元素3s .....所有元素140。对于y变量(3-D),我想做类似的事情,并对“ Hope2,Hope6, 140层中的每层都有Hope7,Hope8和Hope9”。

我首先尝试获取所有x变量的平均值,如下所示:

mean(get, IPSL, MIROC, subsetprime, MPI)                   

但我最终遇到此错误:

Error in mean.default(get, IPSL, MIROC, subsetprime, MPI) : 
'trim' must be numeric of length one
In addition: Warning message:
In if (na.rm) x <- x[!is.na(x)] :
the condition has length > 1 and only the first element will be used

任何帮助将不胜感激!

0 个答案:

没有答案