0

I've plotted this graph. However, I want to add legend which shows the colour and name of the series. I tried to use fill = Freq, bet the results don't even look close to the results I am expecting. Any suggestions?

enter image description here

The code I am using:

p = ggplot(data = data, aes(x = Date, y = Freq)) + geom_line() 
p = p + geom_line(aes(x = Date, y = Freq2), colour = "red")
p = p + geom_line(aes(x = Date, y = Freq3), colour = "blue")
p = p + scale_x_datetime(labels = date_format("%m"),
  breaks = date_breaks("months"))
Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294
AK47
  • 1,318
  • 4
  • 17
  • 30
  • `fill` is for filling stuff in, you need to use `color` inside `aes()` to get a legend for color. To do that, your data will need to be "tidy": you'll want to `reshape2::melt` or `tidyr::gather` it so you have a column called "group" or something with values 1, 2, 3 and a single "Freq" column. Plenty of example [such as this one](http://stackoverflow.com/q/21533442/903061). – Gregor Thomas Apr 29 '15 at 21:40
  • This is not reproducible, but the easiest way would be probably to `melt` your data first and the run `geom_line` once while setting the `color` argument by group. – David Arenburg Apr 29 '15 at 21:40
  • Possible duplicate: http://stackoverflow.com/q/21533442/903061 – Gregor Thomas Apr 29 '15 at 21:41
  • Better duplicate: http://stackoverflow.com/q/10349206/903061 – Gregor Thomas Apr 29 '15 at 21:42

0 Answers0