【问题标题】:Stripplot showing mean+sd [r]显示均值 + 标准差 [r] 的带状图
【发布时间】:2015-04-01 09:04:16
【问题描述】:

您好,我想绘制一个显示均值 + 标准差的带状图。我无法显示箱线图,因为我的值少于 5 个,所以我想使用均值和标准差。我的问题是我无法计算组内的平均值和 sd,而是我得到了两个组中表示的两个平均值,并且与段相同。

require(lattice)

stripplot(l ~ Medium, parameters,

       ylab=list(expression("lag phase - h"),cex=1.5),
       xlab=list("Medium", cex=1.5),
       auto.key=list(columns=2, rectangles=T, points=F, pch=16, at=NULL ),
       ylim=c(-2,15),
       up=parameters$l+parameters$sd.l,
       lo=parameters$l-parameters$sd.l,
       panel=function(x,y,up,lo,...){
         xj=jitter(as.numeric(x), factor=0.5)
         panel.stripplot(xj,y,pch=16 , alpha=0.5 , factor=0.2,
                         cex=1.2 , ...)
         panel.abline(h=0,col="black",...)
         panel.arrows(x0=xj, y0=lo,
                      x1=xj, y1=up,code=3,
                      angle=90, length=0.05
                      ,alpha=0.5)
         panel.dotplot(x=x, y=tapply(y,x,mean), col="red")
         panel.segments(x0=x,x1=x,y0=mean(y)-sd(y),y1=mean(y)+sd(y),col="red")
       }


)

【问题讨论】:

  • 没有任何数据(例如,parameters),我们无法看到发生了什么。

标签: r panel lattice


【解决方案1】:

如果您以Medium 为条件,即~l|Medium 而不是l~Medium,您可以计算面板函数中每个级别的均值和标准差。

例如

stripplot(~Sepal.Length|Species,iris,
  panel=function(x,y,...) {
     m=mean(x)
     panel.stripplot(x,y,...)
     panel.stripplot(m,y,pch="|",cex=2,col=2)
  }
)

否则,您可以使用byaggregate 或类似方法计算stripplot 之外的每个级别的平均值和标准差,然后将它们添加到绘图中。

【讨论】:

    猜你喜欢
    • 2013-05-07
    • 1970-01-01
    • 2012-03-27
    • 1970-01-01
    • 2013-01-10
    • 2014-04-27
    • 2015-04-12
    • 2018-02-01
    • 1970-01-01
    相关资源
    最近更新 更多