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"))
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"))
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
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"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With