0

I got an issue if i want to add a legend in ggplot2 when using the next code:

ggplot() +
   geom_point(data = select, aes(x = Date, y = Netto), colour = "red") +
   geom_point(data = select, aes(x = Date, y = First), colour = "blue") +
   geom_point(data = select, aes(x = Date, y = Second), colour = "black")

I got three different colors, but I can't find how to add a legend in this plot.

A plot of the code

Marco Sandri
  • 23,289
  • 7
  • 54
  • 58
  • https://stackoverflow.com/a/10349375/5316882 – anotherfred Nov 15 '17 at 19:19
  • 1
    Keep it ggplot-like and use just one geom with data in long format. Something like `tidyr::gather(select, key = key, value = value, Netto, First, Second) %>% ggplot(aes(x = Date, y = value, color = key)) + geom_point()` – Tino Nov 15 '17 at 19:23

0 Answers0