我正在创建几个雨云图,并且想知道如何更改样式以使其看起来更自由流动
这是我正在使用的适用于 iris 的代码。
iris %>%
dplyr::group_by(Species) %>%
dplyr::mutate(
mean = mean(Petal.Length),
se = sd(Petal.Length) / sqrt(length(Petal.Length)),
species_y = paste0(Species, "\n(", n(), ")")
) %>%
ungroup() %>%
ggplot(aes(x = Petal.Length, y = species_y)) +
stat_slab(aes(fill = Species)) +
stat_dots(aes(color = Species), side = "bottom", shape = 16) +
scale_fill_brewer(palette = "Set1", aesthetics = c("fill", "color")) +
geom_errorbar(aes(
xmin = mean - 1.96 * se,
xmax = mean + 1.96 * se
), width = 0.2) +
stat_summary(fun = mean, geom = "point", shape = 16, size = 3.0) +
theme_bw(base_size = 10)
“自由流动”的外观可以通过使用
geom_point
和 ggpp::position_jitternudge
来实现
iris %>%
dplyr::group_by(Species) %>%
dplyr::mutate(
mean = mean(Petal.Length),
se = sd(Petal.Length) / sqrt(length(Petal.Length)),
species_y = paste0(Species, "\n(", n(), ")")
) %>%
ungroup() %>%
ggplot(aes(x = Petal.Length, y = species_y)) +
stat_slab(aes(fill = Species)) +
geom_point(aes(color = Species),shape = 16,
position = ggpp::position_jitternudge(height = 0.125, width = 0,
y = -0.125,
nudge.from = "jittered")) +
scale_fill_brewer(palette = "Set1", aesthetics = c("fill", "color")) +
geom_errorbar(aes(
xmin = mean - 1.96 * se,
xmax = mean + 1.96 * se
), width = 0.2) +
stat_summary(fun = mean, geom = "point", shape = 16, size = 3.0) +
theme_bw(base_size = 10) +
theme(legend.position = "top") +
labs(title = "Raincloud plot with ggdist", x = "Petal Length")
平均值集中在给定的示例中,因此不太清楚您在这里的意思。