I am making a faceted ggplot
graphic and would like to put a legend in each facet. For example, if I have the following plot, how could I make a legend in each facet corresponding to the lines that are contained within each facet (instead of one legend as it exists)?
data(mpg)
ggplot(mpg, aes(year, cty, group=manufacturer)) +
geom_line(aes(colour=manufacturer)) + facet_grid(.~drv)
The only solution I can come up with is to make three seperate plots using subsets. Is there a solution using facet_grid()
?