【问题标题】:Error bar lattice dotplot误差线格点图
【发布时间】:2015-03-21 08:04:45
【问题描述】:

我想用误差线和箱线图来表示一个树因子点图。除了我的错误栏重叠之外,我已经完成了几乎所有的图形。具体来说,我的想法是抖动点和误差线

 set.seed(1)

data<-sample(rnorm(50,2,2),40)
sd<-sample(rnorm(50,0.2,2),40)
factor<-sample( LETTERS[1:3], 40, replace=TRUE, prob=c(0.3,.3, 0.3) )
frame<-data.frame(data,sd,factor)
frame<-as.data.frame(frame)
up=frame$data+frame$sd
lo=frame$data-frame$sd
bwplot(data ~ factor, frame,
       ylim=c((min(lo)+0.5*min(lo)),(max(up)-0.5*min(lo))),
       up=frame$data+frame$sd,
       lo=frame$data-frame$sd,
       panel=function(x,y,...){
         panel.bwplot(x,y,...)
         panel.stripplot(x,y,pch=16 ,alpha=0.7, jitter=TRUE, factor=0.2,
                         col="grey",cex=1.2,...)
         panel.arrows(x0=x, y0=lo,
                      x1=x, y1=up,code=3,
                      angle=90, length=0.05)

       }
) 

谢谢!

【问题讨论】:

    标签: r panel lattice


    【解决方案1】:

    分别做抖动

    set.seed(1)
    
    data<-sample(rnorm(50,2,2),40)
    sd<-sample(rnorm(50,0.2,2),40)
    factor<-sample( LETTERS[1:3], 40, replace=TRUE, prob=c(0.3,.3, 0.3) )
    frame<-data.frame(data,sd,factor)
    frame<-as.data.frame(frame)
    up=frame$data+frame$sd
    lo=frame$data-frame$sd
    bwplot(data ~ factor, frame,
           ylim=c((min(lo)+0.5*min(lo)),(max(up)-0.5*min(lo))),
           up=frame$data+frame$sd,
           lo=frame$data-frame$sd,
           panel=function(x,y,...){
             panel.bwplot(x,y,...)
    xj=jitter(as.numeric(x))
             panel.stripplot(xj,y,pch=16 ,alpha=0.7, factor=0.2,
                             col="grey",cex=1.2,...)
             panel.arrows(x0=xj, y0=lo,
                          x1=xj, y1=up,code=3,
                          angle=90, length=0.05)
    
           }
    )
    

    那么条形图和误差线(箭头)的抖动量是相同的。

    【讨论】:

      猜你喜欢
      • 2012-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-06
      • 2021-11-11
      • 1970-01-01
      • 2013-10-13
      • 1970-01-01
      相关资源
      最近更新 更多