0

I have plotted 4 line on a chart:

ggplot() +
  geom_line(benchmark, mapping=aes(Date, EM))+
  geom_line(portfolio, mapping=aes(Date, EM), color="red") +
  geom_line(benchmark, mapping=aes(Date, CB))+
  geom_line(portfolio, mapping=aes(Date, CB), color="red")

How can I add a legend to this?

randomwalker
  • 183
  • 3
  • 11
  • 1
    Please make a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Martin Gal Oct 18 '21 at 16:27
  • 3
    Does this answer your question? [Add legend to ggplot2 line plot](https://stackoverflow.com/questions/10349206/add-legend-to-ggplot2-line-plot) – Jan Boyer Oct 18 '21 at 16:39
  • 3
    The standard way to do this would be to melt/`pivot_longer` your data so that you had only a single `geom_line()` – Ben Bolker Oct 18 '21 at 16:41

0 Answers0