简体   繁体   中英

Draw vertical ending of error bar line in 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

--o--

but I would like to get

|--o--|

I know I can get

|--o--|

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)))

在此处输入图片说明

Please, don't give me solutions that use ggplot2...

I've had this same need in the past, with barchart() instead of with Dotplot() .

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).

Here's what that might look like with 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)))

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM