title: Add legend to ggplot histogram with overlayed density plots
body: <p>I am drawing a histogram using ggplot2 and overlaying a density plot (in black). I then overlay a normal density plot (in red).</p>
  
  <pre><code>set.seed(1234)
  dat &lt;- data.frame(cond = factor(rep(c("A","B"), each=200)), rating = c(rnorm(200),rnorm(200, mean=.8)))
  plot &lt;- ggplot(dat, aes(x = rating)) 
  plot &lt;- plot + geom_histogram(aes(y=..density..), color="black", fill = "steelblue", binwidth = 0.5, alpha = 0.2)
  plot &lt;- plot + geom_density()
  plot &lt;- plot + stat_function(fun = dnorm, colour = "red", args = list(mean = 0.3, sd = 1))
  plot
  </code></pre>
  
  <p>Currently, the plot looks like I want it to look but it is missing a legend explaining the black and red density plots and I have not been able to figure out how to add them. </p>
  
  <p><a href="https://i.stack.imgur.com/wq1C5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wq1C5.png" alt="enter image description here"></a></p>
  
  <p>I am learning R and any help would be greatly appreciated. </p>