好吧,我不能告诉你如何将乘数按组输入stat_summary
.
然而,您的目标似乎是绘制均值和误差线,代表来自平均值的一个标准误差ggplot
在绘图之前没有总结数据集。
有一个mean_se
函数于ggplot2我们可以用它来代替mean_cl_normal
from Hmisc. The mean_se
函数的默认乘数为 1,因此如果我们想要标准误差线,则不需要传递任何额外的参数。
ggplot(mtcars, aes(cyl, qsec)) +
stat_summary(fun.y = mean, geom = "bar") +
stat_summary(fun.data = mean_se, geom = "errorbar")
如果您想使用mean_cl_normal
函数来自Hmisc
,您必须将乘数更改为 1,以便从平均值中得到一个标准误差。这mult
论证是一个论证mean_cl_normal
。您需要传递给正在使用的摘要函数的参数需要以列表的形式提供给fun.args
争论:
ggplot(mtcars, aes(cyl, qsec)) +
stat_summary(fun.y = mean, geom = "bar") +
stat_summary(fun.data = mean_cl_normal, geom = "errorbar", fun.args = list(mult = 1))
在 2.0 之前的版本中ggplot2,可以直接传递参数:
ggplot(mtcars, aes(cyl, qsec)) +
stat_summary(fun.y = mean, geom = "bar") +
stat_summary(fun.data = mean_cl_normal, geom = "errorbar", mult = 1)