我正在使用ggplot进行散点图 . 我想要一个具有特定颜色和填充的点(在 plot
, colour="blue", fill="cyan4"
,例如),但我找不到如何 . 我到目前为止的是:
ggplot(df, aes(own,method)) +
panel.configuration +
scale_shape_identity() + #to use the 'plot' shape format.
geom_point(aes(color = factor(label)), position = "jitter",size=3) +
(在之前的 geom_point
中我尝试添加 shape=21
,就像我在_883287中所做的那样)
scale_colour_manual(values=c("A"="chocolate3","B"="cyan4")) +
scale_fill_manual(values=c("A"="green", "B"="red")) + #DOES NOTHING...
xlim(7,47) + ylim(7,47)+ ... etc.
这就是我没有“shape = 21”的结果
这是我添加"shape=21"时得到的 . 在这两种情况下它都会忽略 scale_fill
我也尝试在geom_point中添加 fill=c("blue","red")
,但R抱怨:"Error: Incompatible lengths for set aesthetics: shape, size, fill" .
有关如何获得它的任何建议?我的代码中 scale_fill
有什么问题?
非常感谢你!
数据(df)看起来像:
21 15 A
24 16 A
24 17 A
28 14 A
24 15 A
22 15 A
20 18 A
24 18 A
34 9 B
38 12 B
41 19 B
42 13 B
36 12 B
40 17 B
41 14 B
37 12 B
40 13 B
37 15 B
35 15 B
1 回答
你必须使用
21 to 25
中的形状 . 这些是具有colour
和fill
属性的:如果你想要
colour
的不同颜色,那么: