[英]Draw vertical ending of error bar line in dotplot
我画dotplot()
使用lattice
或Dotplot()
使用Hmisc
。 当我使用默认参数时,可以绘制没有小垂直结尾的误差线
--o--
但我想得到
| --o-- |
我知道我能得到
| --o-- |
当我使用centipede.plot()从plotrix
或segplot()从latticeExtra
,但是这些解决方案不给我这么好的调理选项为Dotplot()
我正在尝试使用par.settings
的plot.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)))
请不要给我使用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)))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.