2

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)

enter image description here

The only solution I can come up with is to make three seperate plots using subsets. Is there a solution using facet_grid()?

smillig
  • 5,073
  • 6
  • 36
  • 46

0 Answers0