I am trying to add a simple horizontal line to each bar in a barplot using geom_col()
in ggplot2
. The horizontal line will represent the mean of the y-axis, and it will be different for each bar.
For example, using the iris
dataset:
library(ggplot2)
data(iris)
iris %>%
ggplot(aes(x=Species, y=Sepal.Length, fill=Species) +
geom_col(width=0.5) +
theme_classic()
This generate a plot like this:
I know that I can add a horizontal line using geom_hline()
but is there a way to do it so that the horizontal line represents the mean for each species bar?
Thank you so much for any help you are able to provide!