title: Adding an arbitrary function to a ggplot histogram
body: <p>Context:
  I have some data, and I wish to:</p>
  
  <ol>
  <li>plot a histogram of them</li>
  <li>add a kernel density</li>
  <li>add a "theoretical density"</li>
  <li>add a legend to distinguish between 2. and 3.</li>
  </ol>
  
  <p>Consider:</p>
  
  <pre><code>X &lt;- rnorm(1000,0,1)
  Y &lt;- (X^2-1)/2
  ggplot(as.data.frame(Y), aes(x=Y)) + 
      geom_histogram(aes(y=..density..),      
                     binwidth=.2,
                     colour="black", fill="white") +
      geom_density(alpha=.2, fill="#FF6666") 
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/XXiXm.jpg" alt="enter image description here"></p>
  
  <p>This accomplishes 1. and 2., but how can I achieve 3. and 4.? I have written the function I wish to plot:</p>
  
  <pre><code>myfunc &lt;- function(x) {
      2*exp(-x-0.5)/(sqrt(2*x+1)*sqrt(2*pi))
  }
  </code></pre>
  
  <p>Any other comments/critiques are welcome (I am learning)</p>