ggplot中的geom_point(scale_colour_manual)中的填充和边框颜色 [英] Fill and border colour in geom_point (scale_colour_manual) in ggplot

查看:3171
本文介绍了ggplot中的geom_point(scale_colour_manual)中的填充和边框颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ggplot做一个散点图。我想要有一个特定的颜色和填充点(在情节 color =blue,fill =cyan4,例如),但我不能找到如何。这一点是:

I'm doing an scatter plot using ggplot. I would like to have points with a particular colour and fill (in plot, colour="blue", fill="cyan4", for ex.) but I can't find how. What I have to this point is:

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


b $ b

(在之前的 geom_point 中,我尝试添加 shape = 21 c $ c> plot )

(In previous geom_pointI tried adding shape=21 as I would have done in 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

This is what i get without "shape=21"

这是我添加shape = 21时得到的。在这两种情况下,它忽略 scale_fill

This is what I get when I add "shape=21". In both cases it ignores scale_fill

我也试过在geom_point中添加 fill = c(blue,red)但R抱怨:错误:不兼容长度为集美观:形状,大小,填充。

I also tried adding fill=c("blue","red") in geom_point, but R complains: "Error: Incompatible lengths for set aesthetics: shape, size, fill".

有关如何取得建议吗?在我的代码中 scale_fill 有什么问题?

Any suggestions about how to get it? What is wrong with scale_fill in my code?

非常感谢!

资料(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 。这些是颜色填充属性:

You'll have to use shapes from 21 to 25. These are the ones that have colour and fill properties:

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


b $ b

如果你还需要 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"))

这篇关于ggplot中的geom_point(scale_colour_manual)中的填充和边框颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆