Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scale_color_manual() not working

Tags:

r

ggplot2

I am trying to get scale_color_manual() to work in ggplot2 and I am not getting the colors.

I am following the example at this link

My dataset is df given by

structure(list(cond = structure(1:3, .Label = c("A", "B", "C"
), class = "factor"), yval = c(2, 2.5, 1.6)), .Names = c("cond", 
"yval"), class = "data.frame", row.names = c(NA, -3L))

If I use the code in the example to make a bar plot, it works

ggplot(df, aes(x=cond, y=yval, fill=cond)) + geom_bar(stat="identity") + 
    scale_fill_manual(values=c("red", "blue", "green"))

enter image description here

I changed the code to make a scatter-plot, I don't see the points in color now.

ggplot(df, aes(x=cond, y=yval)) + geom_point() + 
    scale_color_manual(values=c("red", "blue", "green"))

enter image description here

This could be trivial, but I am having a hard time finding what I am doing wrong here.

Any help would be much appreciated!!

Thanks

like image 703
Satya Avatar asked Nov 30 '15 21:11

Satya


1 Answers

As per the commenter above, I need to map color to a variable, the following works

ggplot(df, aes(x=cond, y=yval, color = cond)) + geom_point() + 
    scale_color_manual(values=c("red", "blue", "green"))
like image 85
Satya Avatar answered Nov 04 '22 14:11

Satya