Draw vertical ending of error bar line in dotplot

前端 未结 1 1815
陌清茗
陌清茗 2021-01-18 23:50

I am drawing dotplot() using lattice or Dotplot() using Hmisc. When I use default parameters, I can plot error bars witho

相关标签:
1条回答
  • 2021-01-19 00:27

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

    enter image description here

    0 讨论(0)
提交回复
热议问题