title: Combine legend for several stat_function lines and raw data points
body: <p>I have the following code:</p>
  
  <pre><code>library("ggplot2")
  
  data &lt;- data.frame(c(0,1,2,3,4,5), c(-0.2, 0.6, 2.1, 3.8, 6.05, 7.6))
  colnames(data) &lt;- c("X", "Y")
  
  f1 &lt;- function(x)
  {
      x - 0.2
  }
  
  f2 &lt;- function(x)
  {
      ifelse(x&gt;=1.9,-2+x+0.1,0)
  }
  
  m &lt;- function(x)
  {
      f1(x) + f2(x)
  }
  
  graph &lt;- ggplot(data, aes(X,Y, colour="Data")) + geom_point(stat = "identity") + xlim(c(0,5))
  graph &lt;- graph + scale_shape_discrete(name = "Data")
  
  g1 &lt;- stat_function(fun=f1, linetype="dashed", aes(colour="Function A"))
  g2 &lt;- stat_function(fun=f2, linetype="dashed", aes(colour="Function B"))
  gm &lt;- stat_function(fun=m,  aes(colour="Model"))
  
  graph &lt;- graph + g1 + g2 + gm
  graph &lt;- graph + scale_colour_manual(values = c("black", "red", "red", "red"))
  print(graph)
  </code></pre>
  
  <p>That produces the following graph:</p>
  
  <p><img src="https://i.stack.imgur.com/reMs1.png" alt="enter image description here"></p>
  
  <p>Where the legend does not really allow to distinguish between the various functions. I would rather expect a legend like:</p>
  
  <p><img src="https://i.stack.imgur.com/xh7zg.png" alt="enter image description here"></p>
  
  <p>Is it possible to produce something like it?</p>