【发布时间】:2020-07-01 12:31:02
【问题描述】:
我想制作一个散点图,其中每个点都有一个球体。点及其球体都根据某些列值着色。
一个显示我想要的最小示例:
library(ggplot2)
library(vcd) # only needed for example dataset
ggplot(Arthritis, aes(x = ID, y = Age)) +
geom_point(aes(color=Sex), size=10, alpha=.3) +
geom_point(aes(color=Treatment), size=3)
这个“解决方案”的问题在于,使用两个geom_point 层似乎会破坏传说。我想只有一个geom_point 层并使用还添加笔划的形状也会更有意义,所以像这样:
ggplot(Arthritis, aes(x = ID, y = Age)) +
geom_point(aes(color=Sex, fill=Treatment), shape=21, size=5, stroke=5)
这里的传说更有意义,但是,我不知道如何使笔触透明。这很重要,因为当点重叠时您将看不到任何东西。
this 之类的答案不能解决我的问题,因为它们使用恒定颜色,因此可以使用函数 alpha。但是,我不知道是否以及如何将它与取决于数据的颜色一起使用。
TL;DR:我如何绘制具有纯色和透明笔划但不是恒定颜色的geom_points?
【问题讨论】: