scale_color_manual()不起作用

SN2*_*248 4 r ggplot2

我正努力scale_color_manual()工作ggplot2而且我没有得到颜色.

我在这个链接上关注这个例子

我的数据集由.df给出

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))
Run Code Online (Sandbox Code Playgroud)

如果我使用示例中的代码来制作条形图,它就可以工作

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

在此输入图像描述

我更改了代码以制作散点图,我现在看不到颜色的点.

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

在此输入图像描述

这可能是微不足道的,但我很难找到我在这里做错了什么.

任何帮助将非常感激!!

谢谢

SN2*_*248 7

根据上面的评论者,我需要映射color到变量,以下工作

ggplot(df, aes(x=cond, y=yval, color = cond)) + geom_point() + 
    scale_color_manual(values=c("red", "blue", "green"))
Run Code Online (Sandbox Code Playgroud)