title: How to shade part of a density curve in ggplot (with no y axis data)
body: <p>I'm trying to create a density curve in R using a set of random numbers between 1000, and shade the part that is less than or equal to a certain value. There are a lot of solutions out there involving <code>geom_area</code> or <code>geom_ribbon</code>, but they all require a <code>yval</code>, which I don't have (it's just a vector of 1000 numbers). Any ideas on how I could do this?</p>
  
  <p>Two other related questions: </p>
  
  <ol>
  <li>Is it possible to do the same thing for a cumulative density function (I'm currently using <code>stat_ecdf</code> to generate one), or shade it at all?</li>
  <li>Is there any way to edit <code>geom_vline</code> so it will only go up to the height of the density curve, rather than the whole y axis?</li>
  </ol>
  
  <p>Code: (the <code>geom_area</code> is a failed attempt to edit some code I found. If I set <code>ymax</code> manually, I just get a column taking up the whole plot, instead of just the area under the curve)</p>
  
  <pre><code>set.seed(100)
  
  amount_spent &lt;- rnorm(1000,500,150)
  amount_spent1&lt;- data.frame(amount_spent)
  rand1 &lt;- runif(1,0,1000)
  amount_spent1$pdf &lt;- dnorm(amount_spent1$amount_spent)
  
  mean1 &lt;- mean(amount_spent1$amount_spent)
  
  #density/bell curve
  ggplot(amount_spent1,aes(amount_spent)) +
     geom_density( size=1.05, color="gray64", alpha=.5, fill="gray77") +
     geom_vline(xintercept=mean1, alpha=.7, linetype="dashed", size=1.1, color="cadetblue4")+
     geom_vline(xintercept=rand1, alpha=.7, linetype="dashed",size=1.1, color="red3")+
     geom_area(mapping=aes(ifelse(amount_spent1$amount_spent &gt; rand1,amount_spent1$amount_spent,0)), ymin=0, ymax=.03,fill="red",alpha=.3)+
     ylab("")+ 
     xlab("Amount spent on lobbying (in Millions USD)")+
     scale_x_continuous(breaks=seq(0,1000,100))
  </code></pre>