title: ggplot2: how to add the legend for a line added to a scatter plot?
body: <p>I have some x and y data that I would like to compare on a ggplot2 scatter plot.
  I would like to add a unity line (y = x), twofold (y = 2x), half (y = x/2) and smoother lines to help making sense of the data but I cannot find how to add theses lines to the plot's legend. Any idea?</p>
  
  <pre><code>set.seed(123)
  x &lt;- runif(20, 1, 10)
  y &lt;- 0.8 * x + runif(20, -1, 1)
  cat &lt;- factor(c(rep("high", 10), rep("low", 10)))
  d &lt;- data.frame(x, y, cat)
  
  ggplot(data=d) +
       geom_point(aes(x, y, colour=cat)) +
       geom_abline(aes(intercept=0, slope=1), col = "red") +
       geom_abline(aes(intercept=0, slope=0.5), col="blue", linetype="dotted") +
       geom_abline(aes(intercept=0, slope=2), col="blue", linetype="dashed")+
       geom_smooth(aes(x, y))
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/tGL40.png" rel="nofollow noreferrer">y vs x scatter plot in ggplot2</a></p>
  
  <p>I would like the labels 'unity line', 'twofold', 'half', and 'smoother' to appear below the 'high' and 'low' labels in the legend.</p>
  
  <p>Following User3640617's answer, I have tried the following code but the result is still not satisfying because the data points now have a linetype and a smoothing linetype linked to them in the legend.</p>
  
  <pre><code>ggplot(data=d) +
       geom_point(aes(x, y, colour=cat)) +
       geom_abline(aes(intercept=0, slope=1, colour="y = x")) +
       geom_abline(aes(intercept=0, slope=.5, colour="y = x/2")) +
       geom_abline(aes(intercept=0, slope=2, colour="y = 2x")) +
       geom_smooth(aes(x,y, colour="smooth")) +
       scale_color_manual(
          values=c("red", "darkgreen", "black", "blue", "red", "blue")) +
       scale_linetype_manual(
          values=c("blank", "blank", "solid", "dashed", "solid", "dotted")) +
       scale_shape_manual(values=c(1, 1, NA, NA, NA, NA))
  </code></pre>
  
  <p>Also, I do not seem to be able to manually change the tinetypes:</p>
  
  <p><a href="https://i.stack.imgur.com/mM1Ev.png" rel="nofollow noreferrer">scatter plot with ablines and smoother</a></p>
  
  <p>I know, I could simply choose other colors and there would be less confusion but it should be possible to have a legend with only points for points and lines for lines instead of having point <strong>and</strong> lines for both points and lines, or is it not?</p>
  
  <p>ggplot2 seems to be bothered by the addition of <code>color</code> or <code>linetype</code> after the <code>aes</code>. The order of the categories seems to be changed when adding the lines to the legend.</p>