I need to add the legend for some geom_point I am adding in a geom_line graph. The example goes below.
require(dplyr)
require(ggplot2)
set.seed(1111)
My Objects
Sum <- sample(1:50, 10)
year <- c(1990:1999)
index.one <- sample(0:1, 10,replace=TRUE)
index.two <- sample(0:1, 10,replace=TRUE)
df <- data_frame(Sum, year, index.one, index.two)
Graph
graph <- ggplot(df, aes(x=year,y=Sum))+ geom_line() +
geom_point(data=df[df$index.one==1,], aes(x=year, y=Sum), colour="red",
fill="red", shape=22) +
geom_point(data=df[df$index.two==1,], aes(x=year, y=Sum), colour="blue",
fill="blue", shape=22) +
scale_x_continuous(breaks = seq(1990,1999, by=1))
I need to add the legend for the blue and red points in the graph.
Thank you!