【问题标题】:Draw vertical ending of error bar line in dotplot在点图中绘制误差线的垂直末端
【发布时间】:2012-02-27 16:06:29
【问题描述】:

我正在使用latticeDotplot() 使用Hmisc 绘制dotplot()。当我使用默认参数时,我可以绘制没有小的垂直结尾的误差线

--o--

但我想得到

|--o--|

我知道我可以得到

|--o--|

当我使用来自plotrixcentipede.plot() 或来自latticeExtrasegplot() 时,但这些解决方案并没有像Dotplot() 这样给我提供如此好的调节选项。我试图使用plot.linepar.settings,这对于更改误差线颜色、宽度等效果很好,但到目前为止,我在添加垂直结尾方面一直没有成功:

require(Hmisc)
mean = c(1:5)
lo = mean-0.2
up = mean+0.2
d = data.frame (name = c("a","b","c","d","e"), mean, lo, up)
Dotplot(name ~ Cbind(mean,lo,up),data=d,ylab="",xlab="",col=1,cex=1,
        par.settings = list(plot.line=list(col=1),
                       layout.heights=list(bottom.padding=20,top.padding=20)))

请不要给我使用 ggplot2 的解决方案...

【问题讨论】:

标签: r plot lattice


【解决方案1】:

我过去也有同样的需求,使用 barchart() 而不是 Dotplot()

然后我的解决方案是创建一个自定义面板功能:(1)首先执行原始面板功能; (2) 然后使用panel.arrows() 添加误差线(使用双头箭头,其中头部的边缘与轴形成 90 度角)。

这是Dotplot() 的样子:

# 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.15, unit = "native",
                     angle = 90, code = 3)
}

# Use almost the same call as before, replacing the default panel function 
# with your customized function.
Dotplot(name ~ Cbind(mean,lo,up),data=d,ylab="",xlab="",col=1,cex=1,
        panel = mypanel.Dotplot,
        par.settings = list(plot.line=list(col=1),
                       layout.heights=list(bottom.padding=20,top.padding=20)))

【讨论】:

  • 不错的一个!我认为这些面板功能可以发挥作用,但 lattice 手册并不简单,可以采取多种方法来更改参数。干杯伙伴!
  • 嗯,现在我遇到了问题,因为当我再应用两个条件时它不起作用。通过添加另外两个条件来查看:Dotplot(name ~ Cbind(mean,lo,up) | condX * condY,...)。有什么想法吗?
  • @GeekOnAcid -- 我现在没有时间。我建议您在自定义面板功能中添加一行 browser() (第一行就可以了)。然后,当/如果调用该面板函数时,它将中断执行,您可以在那里四处寻找,例如,查看tips &lt;- attr(x, "other") 是否仍然提取正确的数据。 (如果您使用groups= 而不是调节(通过|),我想说您可能需要处理整个panel.superpose() 沼泽,但我相信这可能是不是这里的问题。
  • @GeekOnAcid -- 然后,如果您无法弄清楚,也许可以编辑这个问题,或者将其作为一个新问题提出。如果其他人不捡起来,我会在有机会的时候回来。祝你好运!
  • +1 我也想到了同样的基本想法(自定义面板功能通常是答案),但我看不到错误栏信息的传递方式/位置。您的回答很好地涵盖了这一点,谢谢!
猜你喜欢
  • 1970-01-01
  • 2021-03-07
  • 1970-01-01
  • 1970-01-01
  • 2020-01-23
  • 1970-01-01
  • 1970-01-01
  • 2016-04-29
  • 1970-01-01
相关资源
最近更新 更多