对此可能有一个明显的解决方案,但我对绘图有点天真。我想手动定义point_shape
并point_fill
指示例如性别组。我该怎么做呢?
换句话说,我希望看到例如女性的绿色方块和非女性的蓝色三角形(作为任意示例)。(有评论提到剧情上没有点,但是使用ggridges当前开发版的时候有。)
# Simulate data:
df <- data.frame(female = factor(sample(0:1, size = 500, replace = TRUE)),
intervention = factor(sample(0:1, size = 500, replace = TRUE))) %>%
dplyr::mutate(value = ifelse(female == "1", runif(n = 500, min = 0, max = 100),
rnorm(n = 500, mean = 50, sd = 20)))
# Draw plot:
df %>%
ggplot2::ggplot(aes(y = intervention)) +
ggridges::geom_density_ridges2(aes(x = value,
colour = "black",
fill = female),
scale = .7,
alpha = 0.6,
size = 0.25,
jittered_points = TRUE,
point_shape = 21,
point_size = 0.85,
point_fill = "black")