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