误差棒点阵图 [英] Error bar lattice dotplot

查看:105
本文介绍了误差棒点阵图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to represent a tree factor dotplot with error bar combined with boxplot. I have complete almost all the graphic except that my error bar are overlapped. Concretely my idea is to jitter the dots and the error bars

 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)

       }
) 

谢谢!

推荐答案

单独进行抖动

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)

       }
)

然后,带状图和误差线(箭头)的抖动量相同.

Then the amount of jitter is the same for the stripplot and the error bars (arrows).

这篇关于误差棒点阵图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆