title: ggplot2 shade area under density curve by group
body: <p>I have this dataframe:</p>
  
  <pre><code>set.seed(1)
  x &lt;- c(rnorm(50, mean = 1), rnorm(50, mean = 3))
  y &lt;- c(rep("site1", 50), rep("site2", 50))
  xy &lt;- data.frame(x, y)
  </code></pre>
  
  <p>And I have made this density plot:</p>
  
  <pre><code>library(ggplot2)
  ggplot(xy, aes(x, color = y)) + geom_density()
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/qitOs.jpg" alt="enter image description here"></p>
  
  <p>For <code>site1</code> I need to shade the area under the curve that > 1% of the data. For <code>site2</code> I need to shade the area under the curve that &lt; 75% of the data. </p>
  
  <p>I'm expecting the plot to look something like this (photoshopped). Having been through stack overflow, I'm aware that others have asked how to shade part of the area under a curve, but I cannot figure out how to shade the area under a curve by group.</p>
  
  <p><img src="https://i.stack.imgur.com/YwAlA.jpg" alt="enter image description here"></p>