I was wondering if it was possible to create a legend box for a graph that contains plots of multiple series using ggplot in R. Essentially, this is what I'm doing.
x <- c(1,2,3,4)
y <- c(1.1,1.2,1.3,1.4)
y2 <- c(2.1,2.2,2.3,2.4)
x3 <- c(4,5,6,7)
y3 <- c(3.1,3.2,3.3,3.2)
p1 <- data.frame(x=x,y=y)
p2 <- data.frame(x=x,y=y2)
p3 <- data.frame(x=x3,y=y3)
ggplot(p1, aes(x,y)) + geom_point(color="blue") + geom_point(data=p2, color="red") + geom_point(data=p3,color="yellow")
The command above will make a graph of all three data sets, p1, p2, and p3 in three different colors. I know I haven't as yet specified the names of each data set, but how would I go about creating a legend that identifies the different data sets? In other words, I just want a legend that says that all blue points are P1, all red points are P2, and all yellow points are P3.