Hello,
is there a possibility to calculate subgroup medians within a ggplot histogram (eg. using stat or after_stat functions)?
I have a ggplot like the one below, but I am at a loss as to how to generate separate median lines for every subgroup (created with fill= ) from within ggplot.
library(tidyverse)
attach(starwars)
ggplot()+
aes(x=height, fill = gender)+
geom_histogram(col="white", alpha=0.5, position = 'identity')+
labs(x="height", y=NULL)+
geom_vline(xintercept=median(height, na.rm = TRUE), linetype="dotted")