R语言 雨云图上的自由流动外观

f8rj6qna  于 2023-03-10  发布在  其他
关注(0)|答案(1)|浏览(127)

我正在创建几个雨云图,我想知道如何更改样式,使其看起来更像

那样自由流动,而不是像

那样均匀
这是我正在使用的适合虹膜的代码。

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) +
      theme(legend.position = "top") +
      labs(title = "Raincloud plot with ggdist", x = "Petal Length")

此外,我如何更好地集中我的平均值(图2)?我的代码:

RCday2Sex <- uniquePeople %>%
  dplyr::group_by(sex) %>%
  dplyr::mutate(  mean = mean(thresh.y),
    se = sd(thresh.y) / sqrt(length(thresh.y)),
    sex_y = paste0(sex, "\n(", n(), ")") ) %>% ungroup() %>%
  ggplot(aes(x = thresh.y, y = sex_y, group=sex)) +
  stat_slab(aes(fill = sex), scale = 0.5) +
geom_point(aes(color = sex),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") +
  scale_x_continuous(name="Estimated Nominal Detection Threshold (log10 units)", limits=c(-4.5, 0.5), breaks = seq(-4.5, 0.5, by = 0.5))+ 
  labs(title="Raincloud plots showing odor detection thresholds stratified by sex")
print(RCday2Sex + labs(y = "Sex"))
qvtsj1bj

qvtsj1bj1#

使用geom_pointggpp::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")

均值 * 是 * 在给定的例子中居中,所以它不是真的很清楚你在这里的意思。

相关问题