Width of error bars in line plot using ggplot2

前端 未结 2 1585
轻奢々
轻奢々 2021-01-11 10:43

I have some data with standard errors associated and would like to display these with error bars. That\'s what I have:

# generate some data
hod <- data.f         


        
2条回答
  •  心在旅途
    2021-01-11 11:18

    I have managed to solve a similar issue. In my case I wanted to set both horizontal and vertical errorbar heads to the same size - regardless of the aspect ratio of the plot.

    Based on the original posted code:

    f <- ggplot_build(dayplot)
    
    f$plot$layers[[5]]$geom_params$width  <- 0.02 * diff(f$layout$panel_params[[1]]$x.range)
    f$plot$layers[[6]]$geom_params$height <- 0.02 * diff(f$layout$panel_params[[1]]$y.range)
    
    dayplot <- f$plot
    

    This will set the errorbar head to 2% of the axis range. Maybe could solve your issue.

提交回复
热议问题