I want to add a legend that will tell which color represents which line using ggplot2
.
My code is as follows :
require(lme4)
require(ggplot2)
m1 <
Put the color parameter in aes
and give it the name you want to show in the the legend and then choose the title and colors in scale_color_manual
Example:
library(ggplot2)
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
geom_smooth(aes(color='Smooth 1')) +
geom_smooth(aes(y = (hwy -1), color='Smooth 2')) +
scale_color_manual('Legend Title', values=c('Smooth 1'='blue', 'Smooth 2'='red'))