r - ggplot 中 geom_point (scale_colour_manual) 的填充和边框颜色

标签 r colors ggplot2

我正在使用 ggplot 绘制散点图。我想要具有特定颜色和填充的点(例如,在 plotcolour="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,就像我在plot中所做的那样)

  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”的情况下得到的结果

enter image description here

这就是我添加“shape=21”时得到的结果。在这两种情况下,它都会忽略 scale_fill enter image description here

我还尝试在 geom_point 中添加 fill=c("blue","re​​d") ,但 R 提示:“错误:设置美学的长度不兼容:形状、大小、填充”。

关于如何获取它有什么建议吗?我的代码中的 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

最佳答案

您必须使用 21 到 25 之间的形状。这些是具有 colourfill 属性的:

ggplot(df, aes(own, method)) + 
     geom_point(colour="white", shape=21, size = 4, 
     aes(fill = factor(label))) + 
     scale_fill_manual(values=c("blue", "cyan4"))

如果您还想要不同的颜色 color,那么:

ggplot(df, aes(own, method)) + 
      geom_point(aes(colour=factor(label), 
      fill = factor(label)), shape=21, size = 4) + 
      scale_fill_manual(values=c("blue", "cyan4")) + 
      scale_colour_manual(values=c("white", "black"))

关于r - ggplot 中 geom_point (scale_colour_manual) 的填充和边框颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15965870/

相关文章:

r - ggplot 图例 : position of key relative to labels

r - 如何根据R中的U和V风分量计算风向

r - caret 包中的 createGrid 函数 - 它被删除了吗?

r - 线性模型中删除截距后的显着值变化

python - gtk 中的 alloc_color() 有什么意义?

r - 我如何权衡 stat_smooth 与 ggplot2 中值数的倒数

r - 如何对被视为字符串的数字求和?

colors - 为什么 CSS 过滤器hue-rotate 会产生奇怪的结果?

java - a 轴和 b 轴上的 Lab 图像值均超出范围

r - 使用 ggmap 和 ggplot2 获取带有点的 map