Put whisker ends on boxplot

前端 未结 3 2032
南笙
南笙 2020-11-30 00:35

I would like to put perpendicular lines at the ends of the whiskers like the boxplot function automatically gives.

3条回答
  •  星月不相逢
    2020-11-30 00:59

    To resize the whiskers lines we can use the argument width = 0.5 inside the function: stat_boxplot

    set.seed(42)
    df <- data.frame(cond = factor(rep(c("A", "B"), each = 500)), 
                     value = c(rnorm(500, mean = 1, sd = 0.2), 
                               rnorm(500, mean = 1.5, sd = 0.1))) 
    
    library(ggplot2)
    ggplot(df, aes(x = cond, y = value)) +
           stat_boxplot(geom = "errorbar", width = 0.5) +  
           geom_boxplot() 
    

提交回复
热议问题