Change line colors with ggplot ()

I do not use ggplot2 very much, but today I thought that I would let it switch to some graphs. But I can't figure out how to manually control colors in geom_line()

I am sure that I will miss something simple, but here is my test code:

 x <- c(1:20, 1:20) variable <- c(rep("y1", 20), rep("y2", 20) ) value <- c(rnorm(20), rnorm(20,.5) ) df <- data.frame(x, variable, value ) d <- ggplot(df, aes(x=x, y=value, group=variable, colour=variable ) ) + geom_line(size=2) d 

which gives me the expected result:

enter image description here

I thought that all I needed to do was simple:

 d + scale_fill_manual(values=c("#CC6666", "#9999CC")) 

But it does not change anything. What am I missing?

+46
r ggplot2
Mar 02 '11 at 17:40
source share
1 answer

color and fill are a separate aesthetic. Since you want to change color to color , you need to use the appropriate scale:

 d + scale_color_manual(values=c("#CC6666", "#9999CC")) 

- Is this what you want.

+63
Mar 02 2018-11-11T00:
source share



All Articles