r - 在点图中绘制误差条线的垂直结尾

标签 r plot lattice

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

--o--



但我想得到

|--o--|



我知道我可以得到

|--o--|



当我使用 centipede.plot()来自 plotrixsegplot()来自 latticeExtra ,但这些解决方案并没有给我像 Dotplot() 这样好的调节选项。 .我想玩 par.settingsplot.line ,这对于更改误差线的颜色、宽度等效果很好,但到目前为止我没有成功添加垂直结尾:
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)))

enter image description here

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

最佳答案

我过去也有过同样的需求,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)))

enter image description here

关于r - 在点图中绘制误差条线的垂直结尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9468150/

相关文章:

r - 如何从 `nls`获取估计参数

r - 在 R 中创建多个网络并循环它们

r - 在 R 中自动创建个人图书馆

r - 更改表面颜色(使用lattice::wireframe)

R格包: add legend to a figure

r - R Markdown for windows中代码块的键盘快捷键给出了í

python - Matplotlib:具有不同舱口的堆栈图

r - 如何使用 R 创建叶序螺旋

python - Vincent 图没有显示,没有收到错误

r - 可以在格子和 ggplot2 图中使用多边形()或等效项吗?