title: Using legend with stat_function in ggplot2
body: <p>I am using <code>scale_colour_manual</code> to specify the possible keys in the legend. However, if I use <code>stat_function</code> to plot custom function, the legend is missing.</p>
  
  <p>Any ideas why this happen?</p>
  
  <pre><code>library(ggplot2)
  
  MyFun &lt;- function(x, p) {
    res &lt;- x^(1 / p)
    return(res)
  }
  
  my.df &lt;-data.frame(x = c(0,1))
  plt &lt;- ggplot(my.df, aes(x=x)) +
    stat_function(fun = MyFun, n = 1000, args = list(p = 10), colour = "red") +
    stat_function(fun = MyFun, n = 1000, args = list(p = 3), colour = "blue") +
    stat_function(fun = MyFun, n = 1000, args = list(p = 2), colour = "green") +
    stat_function(fun = MyFun, n = 1000, args = list(p = 1), colour = "orange") +
    scale_colour_manual(values = c("red", "blue", "green", "orange"))
  
  print(plt)
  </code></pre>