我有一个使用ggplot2的双因素条形图,其中我使用mean_se来添加标准错误的错误条。我想使用标准偏差而不是标准误差。
library(tidyverse)
#load diamonds dataset
diamonds <- diamonds
#two-factor dynamite plot
plt <- ggplot(diamonds, aes(cut, price, fill = color)) +
geom_bar(stat = "summary", fun.y = "mean", position = position_dodge(width =
0. 9)) +
geom_errorbar(stat = "summary", fun.data = "mean_se", position =
position_dodge(width = 0.9)) +
ylab("mean price") +
ggtitle("Two-Factor Dynamite plot")
plt
有没有办法与使用mean_se类似,但生成代表一个标准差的误差条? mean_sdl似乎没有这样做。谢谢。
答案 0 :(得分:0)
mean_sdl
接受一个参数mult
,它指定标准偏差的数量 - 默认情况下为mult = 2
。所以你需要通过mult = 1
:
plt <- ggplot(diamonds, aes(cut, price, fill = color)) +
geom_bar(stat = "summary", fun.y = "mean",
position = position_dodge(width = 0.9)) +
geom_errorbar(stat = "summary", fun.data = "mean_sdl",
fun.args = list(mult = 1),
position = position_dodge(width = 0.9)) +
ylab("mean price") +
ggtitle("Two-Factor Dynamite plot")
plt