title: Manual Control of R legend with ggplot2
body: <p>I've got a (x,y) data set and I want to visualize the following:</p>
  
  <ul>
  <li>The scatter plot of the points</li>
  <li>The linear least squares fitting</li>
  <li>A reference line</li>
  </ul>
  
  <p>I'm able to accomplish these tasks with ggplot using geom_point, geom_smooth, and geom_abline.  However, I can't see how to add a legend that lets me annotate what the three graphical objects mean.  Also, my data set is just a vector of x values and a vector of y values (not a data frame).</p>
  
  <p>Here is an example of the code:</p>
  
  <pre><code>library(ggplot2)
  
  set.seed(100)
  
  x = seq(-5, 1, length=50)
  
  c0= 2 
  c1 = 1
  
  y = c0 + c1*x + rnorm(length(x),sd = 0.5)
  
  # Fit a linear model, y~x means y is the response 
  # variable to the x predictor variable
  gp &lt;- ggplot(mapping = aes(x=x,y=y))  
  gp &lt;- gp + geom_point(col="black") 
  gp &lt;- gp + geom_smooth(method=lm, formula = y~x, color="darkred", fill="red") 
  gp &lt;- gp + geom_abline(intercept = 0.,slope = 0., lty="dashed", col="black")
  plot(gp)
  </code></pre>
  
  <p>And I would like to include a legend identifying the data, the least squares fit, and the horizontal line included for reference.</p>