误差条点阵图

时间:2015-03-21 08:04:45

标签: r panel lattice

我想表示一个树因子点图,其中误差条与boxplot结合使用。除了我的错误栏重叠之外,我几乎完成了所有图形。具体来说,我的想法是抖动点和误差条

 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)

       }
) 

谢谢!

1 个答案:

答案 0 :(得分:0)

单独进行抖动

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)

       }
)

然后stripplot和误差条(箭头)的抖动量相同。