我正在尝试创建一个雨云图并让它包含置信区间及其均值(而不是箱线图样式)。我不确定为什么,但是当我运行代码时,置信区间出现了,但我认为它是在
fun=mean
或 mutate
部分中设置的。间隔基于总体平均值而不是组平均值。
这是我正在运行的代码:
uniquePeople %>%
group_by(ageGroup) %>%
mutate(mean = mean(thresh),
se = sd(thresh)/sqrt(length(thresh))) %>%
ungroup() %>%
ggplot(aes(x=thresh, y=ageGroup)) +
stat_slab(aes(fill = ageGroup), scale = 0.5) +
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")
这是输出图。
我从另一个用户那里改编了我的代码:
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")+
labs(title="Raincloud plot with ggdist")
由于某种原因,置信区间也存在同样的问题。提前致谢!!!