3

I'd like to use different legends for 2 of the facets in this plot. The facets for 'Sharks' and 'Tunas' include multiple fish species, so I would like each facet to contain a unique legend for those species. The facets for 'Dorado' and 'Swordfish' only contain one fish species, so no legend is required for them. My plot as it is currently setup provides one common legend for all four facets, and because that includes so many species, it is difficult to distinguish the subtle differences in color shades. I think it would be better just have a different legend for the two facets that have multiple species, and place those legends in the upper right corner of those facets.

ggplot(data=table3, aes(x=Year, y=Weight, fill=Species, color=Species)) + theme_bw() + geom_line(aes(linetype=Group)) 
+
facet_wrap(~Group, scales = "free", ncol=2) + xlab("Year") + ylab("Landings (round metric tons)") + guides(color = "legend", linetype ="none")

Faceted plot

shadow
  • 21,823
  • 4
  • 63
  • 77
ament
  • 83
  • 1
  • 8
  • 2
    `ggplot2` only has a single legend per attribute by design, so that is not easily doable. You can trick things sometimes (by using different attributes), or you can construct your own legend with lower-level primitives. Or maybe you just do a different plot per facet. Can't think of another approach. – Mike Wise Jan 22 '16 at 23:38
  • 2
    I would also suggest making two separate plots, instead of using facets. The design philosophy behind facets are that they are subplots that share aesthetics, which is not what you want. You can look at the `cowplot` package for a nice way to align those and have everything sorted out that way. – Axeman Jan 22 '16 at 23:43
  • 2
    Possible duplicate of [place a legend for each facet\_wrap grid in ggplot2](http://stackoverflow.com/questions/14840542/place-a-legend-for-each-facet-wrap-grid-in-ggplot2) – mlt May 05 '16 at 06:00

0 Answers0