【发布时间】:2016-12-24 10:16:12
【问题描述】:
这是一个愚蠢的data.frame:
df <- read.table(textConnection(
"pole medal bag x y
north gold paper 0.852 0.423
north gold plastic 0.277 0.055
north silver paper 0.257 0.211
north silver plastic 0.457 0.614
north bronze paper 0.825 0.299
north bronze plastic 0.672 0.126
south gold paper 0.482 0.764
south gold plastic 0.603 0.869
south silver paper 0.327 0.451
south silver plastic 0.147 0.672
south bronze paper 0.140 0.466
south bronze plastic 0.833 0.325
"), header = TRUE)
我知道如何为这些数据绘制散点图,使用颜色和形状来指示两个因素属性;例如:
library(ggplot2)
ggplot(data = df, aes(x = x, y = y)) +
geom_point(size = 4, aes(shape = pole, color = bag))
我想再添加一个点特征来指示第三个因素属性(在本例中为medal)。想到的一种可能性是彩色轮廓。
有没有方便的方法来做到这一点? (问题的一个棘手方面是轮廓的调色板必须与用于点填充的调色板不同,因为对于每个点,轮廓和填充必须在视觉上区分。)
更新:
当我尝试 Gregor 的建议时,点看起来是正确的,但图例却搞砸了:
【问题讨论】:
-
您可能需要为填充与颜色建立自己的配色方案,以使其看起来不错。加上一些传奇作品。如:
scale_fill_manual(values = c("pink", "white")) + scale_color_manual(values = c("brown", "gold", "grey74")) + guides(fill = guide_legend(override.aes = list(color = c("pink", "white"))), color = guide_legend(override.aes = list(shape = 21))) -
为什么这个问题被否决了?
-
@kjo,可能是因为
geom_point的文档中对此进行了详细讨论。还有see for example here和 -
示例here中的讨论说:“对于有边框的形状(比如21),你可以分别给里面和外面上色。使用描边美学来修改边框的宽度"
-
@Axeman:好的,我们认为“讨论了一定长度”的内容有所不同。 aosmith 和 Gregor 给出的必要的
scale_*和guide修改未在文档中明确提及。这些都是我正在寻找的答案的一部分。但是,嘿,没关系:这不是我的问题第一次被那些一开始就懒得理解这个问题的人投反对票。