Hi all,
I have a question about adding separate horizontal lines to different panels in ggplot bar charts.
For example, the dataframe is like this:
a
> value group level
> -3.659497 1 Level 1
> -2.372006 2 Level 1
> -3.435326 3 Level 1
> -3.492647 4 Level 1
> -3.589319 5 Level 1
> -5.498233 1 Level 2
> -2.720646 2 Level 2
> -5.055747 3 Level 2
> -5.113817 4 Level 2
> -5.311411 5 Level 2
I draw bar plots and combine them together using the code below:
> a.bar= ggplot(a,aes(group,value))+
> geom_bar(position='dodge',stat='identity')+ facet_wrap(~level,ncol=1)+
> geom_hline(yintercept=mean(a$value))
> print(a.bar)
However, I want to add the mean value of Level 1 and Level 2 on the two panels (Level 1 and Level 2) separately, rather than using a whole mean value as the horizontal lines in each panel. How could I achieve this? Thanks for your help.