【发布时间】:2022-01-21 05:03:13
【问题描述】:
我需要一些帮助来确定使用以下 R 脚本估计标准误差:
library(ggplot2)
library(ggpubr)
library(Hmisc)
data("ToothGrowth")
ToothGrowth$dose <- as.factor(ToothGrowth$dose)
head(ToothGrowth, 4)
theme_set(
theme_classic() +
theme(legend.position = "top")
)
# Initiate a ggplot
e <- ggplot(ToothGrowth, aes(x = dose, y = len))
# Add mean points +/- SD
# Use geom = "pointrange" or geom = "crossbar"
e + geom_violin(trim = FALSE) +
stat_summary(
fun.data = "mean_sdl", fun.args = list(mult = 1),
geom = "pointrange", color = "black"
)
# Combine with box plot to add median and quartiles
# Change fill color by groups, remove legend
e + geom_violin(aes(fill = dose), trim = FALSE) +
geom_boxplot(width = 0.2)+
scale_fill_manual(values = c("#00AFBB", "#E7B800", "#FC4E07"))+
theme(legend.position = "none")
非常感谢您的帮助 亲切的问候
【问题讨论】:
-
您可以改用
fun.data = "mean_se"。 -
这能回答你的问题吗? Standard error bars using stat_summary
-
@teunbrand 我用 mean_se 表示标准误差,还用 mean_cl_normal 表示 95%CI 和标准差;但我看不到它们之间的任何变化。您能否检查一下我的原始问题的编辑版本,现在也有截图。感谢 cmets
-
这是
stat_summary()版本的情节,我不知道如何用箱线图来做。请注意,当您使用stat_summary()时,您不会保存对象。因此,当您制作箱线图时,它没有stat_summary()。