问题描述
我正在使用lattice
绘制dotplot()
或使用Hmisc
绘制Dotplot()
.使用默认参数时,可以绘制没有垂直尾部的误差线
I am drawing dotplot()
using lattice
or Dotplot()
using Hmisc
. When I use default parameters, I can plot error bars without small vertical endings
但是我想得到
我知道我可以得到
当我使用 centipede.plot()从plotrix
或 segplot()来自latticeExtra
,但是这些解决方案并没有像Dotplot()
那样给我提供很好的条件选项.我正在尝试使用plot.line
的par.settings
,它可以很好地用于更改错误栏的线条颜色,宽度等,但是到目前为止,我在添加垂直结尾方面一直没有成功:
when I use centipede.plot() from plotrix
or segplot() from latticeExtra
, but those solutions don't give me such nice conditioning options as Dotplot()
. I was trying to play with par.settings
of plot.line
, which works well for changing error bar line color, width, etc., but so far I've been unsuccessful in adding the vertical endings:
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的解决方案...
Please, don't give me solutions that use ggplot2...
推荐答案
我过去也有相同的需求,使用barchart()
而不是Dotplot()
.
I've had this same need in the past, with barchart()
instead of with Dotplot()
.
然后,我的解决方案是创建一个自定义面板功能:(1)首先执行原始面板功能; (2)然后使用panel.arrows()
添加误差线(使用双向箭头,其中箭头的边缘与轴形成90度角).
My solution then was to create a customized panel function that: (1) first executes the original panel function ; and (2) then uses panel.arrows()
to add the error bar (using a two-headed arrow, in which the edges of the head form a 90 degree angle with the shaft).
这是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)))
这篇关于在点图中绘制误差线的垂直末端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!