Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two geom_points add a legend

Tags:

I plot a 2 geom_point graph with the following code:

source("http://www.openintro.org/stat/data/arbuthnot.R") library(ggplot2) ggplot() +   geom_point(aes(x = year,y = boys),data=arbuthnot,colour = '#3399ff') +   geom_point(aes(x = year,y = girls),data=arbuthnot,shape = 17,colour = '#ff00ff') +   xlab(label = 'Year') +   ylab(label = 'Rate') 

I simply want to know how to add a legend on the right side. With the same shape and color. Triangle pink should have the legend "woman" and blue circle the legend "men". Seems quite simple but after many trial I could not do it. (I'm a beginner with ggplot).

enter image description here