0

I am trying to create some vizualizations with ggplot2 in R but the colors don't match what is in my code and the legend. One line is always pink.

Here is my code:

point = format_format(big.mark = " ", decimal.mark = ",", scientific = FALSE)
p7=ggplot(data) + 
  geom_line(aes(x=date, y = Neutral, color="deepskyblue", linetype="solid")) +
  geom_line(aes(x=date, y = NonNeutral, color="deepskyblue3", linetype="solid"))
p7 + scale_y_continuous(labels = point) + ggtitle("") + 
  xlab("") + ylab("") 

I am getting this graph: enter image description here

For some reason one of the lines is always pink no matter which color I specify. I need the legend and need colors to match what is said in the legend.

Any insight how to fix this is very welcome.

Thanks for considering this.

stefan
  • 90,330
  • 6
  • 25
  • 51
Thierry
  • 21
  • 2
  • 1
    When you do `color="deepskyblue"` inside `aes()` it it treated as the name of a category for which `ggplot2` picks a color from its default color palette. Instead do e.g. `color="neutral"` then set you colors via `+ scale_color_manual(values = c(neutral = "deepskyblue", ...))`. For more help please provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including a snippet of your data or some fake data. – stefan Aug 20 '23 at 10:52

0 Answers0