0

Possible Duplicate:
ggplot2 add a legend for several stat_functions

I'm trying to superimpose 3 functions (using stat_function) on top of a scatterplot (geom_point), and add a legend for the superimposed functions. I've successfully produced a plot with the functions, but I'm not sure how to add the legend.

ggplot(questionnaire,aes(A,B)) + 
  geom_point() + 
  stat_function(...,colour="blue") + 
  stat_function(...,colour="red") + 
  stat_function(...colour="green")

Any help with how to add a legend that explains what each of the different colored lines is would be appreciated.

Community
  • 1
  • 1
Aneesh
  • 1
  • @mplourde I get an error that says "Error: Labels can only be specified in conjunction with breaks". I get this error when trying to use scale_colour_manual in my own code, as well as with simply running the sample code given in the answer. Any ideas? – Aneesh Jun 12 '12 at 19:55
  • You are likely using an old version of ggplot2 (and possibly an old version of R as well). The code in that answer works with ggplot2 0.9.1. (The way in which labels and breaks were specified changed somewhat between versions.) – joran Jun 12 '12 at 21:09

0 Answers0