R语言 包含置信区间(平均值)的雨云图

eqoofvh9  于 2023-03-05  发布在  其他
关注(0)|答案(1)|浏览(132)

我试图创建一个95%置信区间的雨云图,但是我的代码继续生成一个箱线图区间的雨云图。这意味着黑色圆圈是中位数而不是平均值。我如何改变我的代码添加误差条来实现这一点?
这里有两个代码,我尝试创建的雨云图,但没有与平均值。我附上了如何图看。最后一张图片是我希望如何图看。What I want it to look like here Image 3
Image 1

df %>%ggplot(aes(x=thresh.x, y=sex, fill=sex))+stat_slab(aes(thickness = stat(pdf*n)),scale = 0.7) +stat_dotsinterval(side = "bottom",scale = 0.7,slab_size = NA)

Image 2

df %>%
  ggplot(aes(x=thresh.x, y=sex, fill=sex))+
  stat_slab(aes(thickness = stat(pdf*n)), 
                scale = 0.7) +
  stat_dotsinterval(side = "bottom",
                    scale = 0.7,
                    slab_size = NA) + 
  scale_fill_brewer(palette = "Set1") +
  theme(legend.position = "top")+
  scale_x_continuous(limits = c(-4.5, .5), breaks = seq(-4.5, 0.5, by = 0.5))+
  labs(title="Raincloud plot with ggdist")

可以在这里找到:https://z3tt.github.io/Rainclouds/

ggplot(iris, aes(Species, Sepal.Width)) + 
  ggdist::stat_halfeye(adjust = .5, width = .3, .width = c(0.5, 1)) + 
  ggdist::stat_dots(side = "left", dotsize = .4, justification = 1.05, binwidth = .1)
aamkag61

aamkag611#

感谢您使用最小可重复示例更新您的问题。一个潜在的"简单"解决方案是将均值添加到现有图中:

library(tidyverse)
library(ggdist)

iris %>%
  ggplot(aes(x=Petal.Length, y=Species))+
  stat_slab(aes(fill=Species), scale = 0.7) +
  stat_dotsinterval(aes(fill=Species),
                    side = "bottom",
                    scale = 0.7,
                    slab_size = NA) + 
  scale_fill_brewer(palette = "Set1") +
  stat_summary(aes(color = "mean"), 
               fun=mean, geom="point", shape="|", size=5) +
  theme_bw(base_size = 16) +
  theme(legend.position = "top")+
# scale_x_continuous(limits = c(-4.5, .5), breaks = seq(-4.5, 0.5, by = 0.5))+
  labs(title="Raincloud plot with ggdist") +
  scale_color_manual(name = "",
                     values = c("mean" = "cyan"))

创建于2023年3月2日,使用reprex v2.0.2
如果这不合适,我想你需要自己计算统计数据。

iris %>%
  group_by(Species) %>%
  mutate(mean = mean(Petal.Length),
         se = sd(Petal.Length)/sqrt(length(Petal.Length))) %>%
  ungroup() %>%
  ggplot(aes(x=Petal.Length, y=Species)) +
  stat_slab(aes(fill = Species)) +
  stat_dots(side = "bottom", shape = 16) + 
  scale_fill_brewer(palette = "Set1") +
  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=2.5) +
  theme_bw(base_size = 16) +
  theme(legend.position = "top")+
  # scale_x_continuous(limits = c(-4.5, .5), breaks = seq(-4.5, 0.5, by = 0.5))+
  labs(title="Raincloud plot with ggdist")

创建于2023年3月2日,使用reprex v2.0.2
这能解决你的问题吗?

相关问题