Satya
Satya

Reputation: 1800

scale_color_manual() not working

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

Upvotes: 13

Views: 36295

Answers (1)

Satya
Satya

Reputation: 1800

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"))

Upvotes: 17

Related Questions