【发布时间】:2018-05-01 06:05:07
【问题描述】:
出于某种愚蠢的原因,我需要创建一个箱线图,其中中线是 mean 而不是中位数。我已经检查了 stackoverflow 并找到了 adding 平均线的示例,但不完全是我需要的。我尝试使用 stat_smooth 但没有骰子。有什么想法吗?
代码如下:
dust <- c(4.5, 3.7, 5, 5.2, 8.5, 6.6, 4.7, 5, 5.7, 4.3, 2.3, 7.6, 5.2,
6, 8.7, 7.5, 7.7, 11, 9, 6.5, 8.7, 5, 2.2, 7.5, 7.5, 3.5)
wind <- c("Present", "Absent", "Absent", "Absent", "Absent", "Absent",
"Absent", "Absent", "Absent", "Present", "Absent", "Absent",
"Present", "Present", "Absent", "Absent", "Absent", "Absent",
"Absent", "Present", "Absent", "Present", "Absent", "Absent",
"Absent", "Present")
df <- data.frame(dust,wind)
plot <- ggplot(data=df,aes(x=wind,y=dust))+geom_boxplot()+stat_smooth()
plot
【问题讨论】:
-
geom_boxplot 可以采用更详细的参数,如中间(即平均值)、ymin、lower 等。查看 ?geom_boxplot
-
geom_boxplot(middle = mean(dust))。另外,为什么stat_smooth?它有什么作用? -
@RuiBarradas 不要忘记
aes:geom_boxplot(aes(middle = mean(dust))) -
@neilfws 是的,谢谢。对不起,我误导了OP。
-
@Chris 到目前为止有两个支持,这似乎是一个值得未来用户参考的问题。你不会发表你的评论作为答案吗?