gpt4 book ai didi

r - 使用 R.zoo 绘制带有误差线的多个系列

转载 作者:行者123 更新时间:2023-12-04 10:16:00 26 4
gpt4 key购买 nike

我有看起来像这样的数据:

   > head(data)
groupname ob_time dist.mean dist.sd dur.mean dur.sd ct.mean ct.sd
1 rowA 0.3 61.67500 39.76515 43.67500 26.35027 8.666667 11.29226
2 rowA 60.0 45.49167 38.30301 37.58333 27.98207 8.750000 12.46176
3 rowA 120.0 50.22500 35.89708 40.40000 24.93399 8.000000 10.23363
4 rowA 180.0 54.05000 41.43919 37.98333 28.03562 8.750000 11.97061
5 rowA 240.0 51.97500 41.75498 35.60000 25.68243 28.583333 46.14692
6 rowA 300.0 45.50833 43.10160 32.20833 27.37990 12.833333 14.21800

每个组名都是一个数据系列。由于我想分别绘制每个系列,因此我将它们分开如下:
> A <- zoo(data[which(groupname=='rowA'),3:8],data[which(groupname=='rowA'),2])
> B <- zoo(data[which(groupname=='rowB'),3:8],data[which(groupname=='rowB'),2])
> C <- zoo(data[which(groupname=='rowC'),3:8],data[which(groupname=='rowC'),2])

预计到达时间:
Thanks to gd047: Now I'm using this:

z <- dlply(data,.(groupname),function(x) zoo(x[,3:8],x[,2]))

生成的动物园对象如下所示:
> head(z$rowA)
dist.mean dist.sd dur.mean dur.sd ct.mean ct.sd
0.3 61.67500 39.76515 43.67500 26.35027 8.666667 11.29226
60 45.49167 38.30301 37.58333 27.98207 8.750000 12.46176
120 50.22500 35.89708 40.40000 24.93399 8.000000 10.23363
180 54.05000 41.43919 37.98333 28.03562 8.750000 11.97061
240 51.97500 41.75498 35.60000 25.68243 28.583333 46.14692
300 45.50833 43.10160 32.20833 27.37990 12.833333 14.21800

因此,如果我想针对时间绘制 dist.mean 并为每个系列包含等于 +/- dist.sd 的误差线:
  • 我如何结合 A、B、C dist.mean 和 dist.sd?
  • 如何制作条形图,或者更好的是制作结果对象的折线图?
  • 最佳答案

    这是我将尝试这样做的方式的提示。我忽略了分组,因此您必须对其进行修改以包含多个系列。我也没有使用过动物园,因为我知道的不多。

    g <- (nrow(data)-1)/(3*nrow(data))

    plot(data[,"dist.mean"],col=2, type='o',lwd=2,cex=1.5, main="This is the title of the graph",
    xlab="x-Label", ylab="y-Label", xaxt="n",
    ylim=c(0,max(data[,"dist.mean"])+max(data[,"dist.sd"])),
    xlim=c(1-g,nrow(data)+g))
    axis(side=1,at=c(1:nrow(data)),labels=data[,"ob_time"])

    for (i in 1:nrow(data)) {
    lines(c(i,i),c(data[i,"dist.mean"]+data[i,"dist.sd"],data[i,"dist.mean"]-data[i,"dist.sd"]))
    lines(c(i-g,i+g),c(data[i,"dist.mean"]+data[i,"dist.sd"], data[i,"dist.mean"]+data[i,"dist.sd"]))
    lines(c(i-g,i+g),c(data[i,"dist.mean"]-data[i,"dist.sd"], data[i,"dist.mean"]-data[i,"dist.sd"]))
    }

    alt text

    关于r - 使用 R.zoo 绘制带有误差线的多个系列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3025347/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com