雨云图上自由流动的外观

问题描述 投票:0回答:1

我正在创建几个雨云图,并且想知道如何更改样式以使其看起来更自由流动

这是我正在使用的适用于 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)
r ggplot2 mean interaction
1个回答
0
投票

“自由流动”的外观可以通过使用

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

平均值集中在给定的示例中,因此不太清楚您在这里的意思。

© www.soinside.com 2019 - 2024. All rights reserved.