2012-02-28 54 views
5

这个问题是从Draw vertical ending of error bar line in dotplot意外的后续行动。引用的问题被成功解决了 - 但有一个警告。当我向点图引入多于三个条件时,它不想绘制垂直刻度| --o-- |在错误栏的结尾处。错误栏蜱| --o-- |不要在dotplot中绘制多于三个条件

由于@Josh的意见建议,我注入browser()到的功能,吸引了更新panel.Dotplot,看看有什么不顺心的第一线,但它并没有与任何帮助我解决这个问题出来了。下面是四个条件Dotplot()的示例代码,其中更新的panel.Dotplot函数不起作用。它会工作,如果你减少的条件数(检查答案上面引用的问题):

require(Hmisc) 
#Fake conditions 
mean = c(1:18) 
lo = mean-0.2 
up = mean+0.2 
name = c("a","b","c") 
cond1 = c("A","B","C") 
cond2 = c(rep("E1",9),rep("E2",9)) 
d = data.frame (name = rep(name,6), mean, lo, up, 
       cond1=rep(cond1,each=3,times=2), cond2) 
# Create the customized panel function 
mypanel.Dotplot <- function(x, y, ...) { 
     panel.Dotplot(x,y,...) 
     tips <- attr(x, "other") 
     panel.arrows(x0 = tips[,1], y0 = y,x1 = tips[,2], 
       y1 = y,length = 0.1, unit = "native", 
       angle = 90, code = 3) 
} 
#Draw Dotplot - `panel.Dotplot` doesn't change anything 
setTrellis() 
Dotplot(name ~ Cbind(mean,lo,up) | cond1 * cond2, data=d, ylab="", xlab="",col=1, 
     panel = mypanel.Dotplot) 

enter image description here

回答

5

误差条实际上被渲染,但不可见,因为它们很短长度(±0.2个单位)。增加误差为±在以下1次的结果(I也增加了在panel.arrows指定的length已经 - 即错误杆顶盖长度 - 至0.5):

lattice error bars

如果您的真正的数据是如此精确的相对到x值的范围,那么您可能需要考虑更小的点(因此它们不容易掩盖误差条)或夸大x轴的布局。例如,下面使用你原来的±0.2单位的错误,和你原来的箭头帽length 0.1:

Dotplot(name ~ Cbind(mean,lo,up) | cond1 * cond2, data=d, ylab="", xlab="", 
    col=1, panel = mypanel.Dotplot, pch=20, cex=0.4, layout=c(1, 6), strip=FALSE, 
    strip.left=strip.custom(par.strip.text=list(cex=0.75), bg=0, fg=0)) 

lattice precise error bars

+0

现在,我得到完整的故事,欢呼声@jbaums!克利夫兰会为我们感到骄傲;-) – 2012-02-29 09:38:00