0

So in ggplot2, I can't figure out how to control both the legend name of a line and the color of that line.

For example:

ggplot(data.frame(x=1:5,y=1:5), aes(x,y,colour='name')) + geom_line()

creates a red line with legend name "name", while if I instead use the argument geom_line(colour='blue'), I get a blue line with no legend name:

enter image description here enter image description here

How do I control both the color of the line AND the title of my line in the legend??

theforestecologist
  • 4,667
  • 5
  • 54
  • 91
  • 4
    Possible duplicate of [Controlling linetype, color and label in ggplot legend](https://stackoverflow.com/questions/46396292/controlling-linetype-color-and-label-in-ggplot-legend) or [this](https://stackoverflow.com/questions/23177365/assign-colour-to-each-line-in-ggplot2) or [that](https://stackoverflow.com/questions/5171263/changing-line-colors-with-ggplot) – Roman Apr 05 '18 at 14:09
  • To downvoter: downvoting possible duplicates doesn't make any sense. The question is written well and to specification according to the help page, so it's a _good_ question. In this case, it does appear to be a dupe, but future users landing on this question first would benefit to know it was a well asked question. Downvoting should not be used as "punishment" for asking a dupe question. SMH. – theforestecologist Apr 05 '18 at 14:13
  • 1
    and see [the cheetsheet](https://www.rstudio.org/links/data_visualization_cheat_sheet) or the hundreds of good tutorials [here](http://r4ds.had.co.nz/data-visualisation.html) or [there](http://ggplot2.tidyverse.org/reference/scale_manual.html) – Roman Apr 05 '18 at 14:17
  • Thanks, @Jimbou! – theforestecologist Apr 05 '18 at 14:17

0 Answers0