I\'m using ggplot2 to create panels of histograms, and I\'d like to be able to add a vertical line at the mean of each group. But geom_vline() uses the same intercept for each
One way is to construct the data.frame with the mean values before hand.
library(reshape)
dfs <- recast(data.frame(cat1, cat2, val), cat1+cat2~variable, fun.aggregate=mean)
qplot(val, data=df, geom="histogram", binwidth=0.2, facets=cat1~cat2) + geom_vline(data=dfs, aes(xintercept=val), colour="red") + geom_text(data=dfs, aes(x=val+1, y=1, label=round(val,1)), size=4, colour="red")