title: Plot quantiles of distribution in ggplot2 with facets
body: <p>I'm currently plotting a number of different distributions of first differences from a number of regression models in ggplot. To facilitate interpretation of the differences, I want to mark the 2.5% and the 97.5% percentile of each distribution. Since I will be doing quite a few plots, and because the data is grouped in two dimension (model and type), I would like to define and plot the respective percentiles in the ggplot environment. Plotting the distributions using facets gets me to exactly where I want except for the percentiles. I could of course do this more manually, but I would ideally want to find a solution where I am still able to use <code>facet_grid</code>, since this spared me a lot of hassle trying to fit the different plots together.</p>
  
  <p>Here's an example using simulated data:</p>
  
  <pre><code>df.example &lt;- data.frame(model = rep(c("a", "b"), length.out = 500), 
                        type = rep(c("t1", "t2", "t2", "t1"), 
                        length.outh = 250), value = rnorm(1000))
  
   ggplot(df.example, aes(x = value)) +
   facet_grid(type ~ model) +
   geom_density(aes(fill = model, colour = model))
  </code></pre>
  
  <p>I've tried to add quantiles in two ways. The first one produces an error message:</p>
  
  <pre><code> ggplot(df.example, aes(x = value)) +
   facet_grid(. ~ model) +
   geom_density(aes(fill = model, colour = model)) +
   geom_vline(aes(x = value), xintercept = quantile(value, probs = c(.025, .975)))
  </code></pre>
  
  <blockquote>
  <pre><code>Error in quantile(value, probs = c(0.025, 0.975)) : object 'value' not found
  </code></pre>
  </blockquote>
  
  <p>While the second one gets me the quantiles for the the complete variable and not for the sub-densities. That is, the plotted quantiles are identical for all four densities.</p>
  
  <pre><code> ggplot(df.example, aes(x = value)) +
   facet_grid(type ~ model) +
   geom_density(aes(fill = model, colour = model)) +
   geom_vline(xintercept = quantile(df.example$value, probs = c(.025, .975)))
  </code></pre>
  
  <p>I consequently wonder if there is a way to plot the specific quantiles for each subgroup within the ggplot2 environment?</p>
  
  <p>Greatly appreciate any input.</p>