title: Why doesn't geom_hline generate a legend in ggplot2?
body: <p>I have some code that is plots a histogram of some values, along with a few horizontal lines to represent reference points to compare against. However, ggplot is not generating a legend for the lines. </p>
  
  <pre><code>library(ggplot2)
  library(dplyr)
  
  ## Siumlate an equal mix of uniform and non-uniform observations on [0,1]
  x &lt;- data.frame(PValue=c(runif(500), rbeta(500, 0.25, 1)))
  y &lt;- c(Uniform=1, NullFraction=0.5) %&gt;% data.frame(Line=names(.) %&gt;% factor(levels=unique(.)), Intercept=.)
  ggplot(x) +
      aes(x=PValue, y=..density..) + geom_histogram(binwidth=0.02) +
      geom_hline(aes(yintercept=Intercept, group=Line, color=Line, linetype=Line),
                 data=y, alpha=0.5)
  </code></pre>
  
  <p>I even tried reducing the problem to just plotting the lines:</p>
  
  <pre><code>ggplot(y) +
      geom_hline(aes(yintercept=Intercept, color=Line)) + xlim(0,1)
  </code></pre>
  
  <p>and I still don't get a legend. Can anyone explain why my code isn't producing plots with legends?</p>