All,
I have a chart that has 2 histograms in which I also plotted lines representing the 20th, 40th, 60th and 80th percentiles, the code below reproduces a similar chart with dummy data
data <- rbind(data.frame(x=rnorm(1000,0,1),g="one"),data.frame(x=rnorm(1000,0.2,1.5),g="two"))
q1 = melt(ddply(melt(data,id.vars="g"),.(g),summarise,q20=quantile(value,.2,na.rm=T),
q40=quantile(value,.4,na.rm=T),q60=quantile(value,.6,na.rm=T),q80=quantile(value,.8,na.rm=T)))
ggplot(data,aes(x=x,fill=g))+
geom_vline(data=q1,aes(xintercept=value,group=variable),linetype=2,color="black")+
#stat_bin(aes(y=..count../sum(..count..)),binwidth=0.1,alpha=0.4,geom="bar")+
geom_histogram(aes(y=..count../sum(..count..)),alpha=0.75,binwidth=0.1)+facet_grid(g~.)+theme_bw()+coord_cartesian(xlim=c(-3,3))
I want to add a shaded region (maybe in gray) between the 40 and 60th lines to show the middle quintile - I would like for the region to be data driven (I am using dataframe q1 which is data derived and that is acceptable, I just do not want to have to enter value manually)
How can this be accomplished? I have not been able to do it
thanks for all the help