2020-11-20

How to change the width of error bars in ggplot2

Problem

We want to change the width of the error bars in a boxplot created with ggplot2. We use stat_boxplot(geom ='errorbar') to add error bars.

library(ggplot2)
ggplot(iris, aes(factor(Species), Sepal.Width, fill = Species)) +
    geom_boxplot() + 
    stat_boxplot(geom ='errorbar')

Solution

We use the argument width inside stat_boxplot.

library(ggplot2)
ggplot(iris, aes(factor(Species), Sepal.Width, fill = Species)) +
  geom_boxplot() + 
  stat_boxplot(geom ='errorbar', width = 0.5) 

No hay comentarios:

Publicar un comentario

Nube de datos