I have the next sample data
sample_data<-data.frame(nros=rnorm(20,mean=5,sd=2),group=rep(c("A","B","C","D"),5))
I want to add text in each plot, but this text should be dynamic. I mean I want for each histogram the mean of the variable nros in each group. I have tried this but I got the same mean for each plot.
sample_data|>ggplot(aes(x=nros))+geom_histogram()+
geom_vline(aes(xintercept=mean(nros)),color="blue", linetype="dashed", size=1)+xlim(0,30)+
geom_text(aes(x=mean(nros)+3,label=mean(nros),y=0.2))+facet_wrap(~group)