小编Bil*_*son的帖子

如何使用geom_boxplot绘制平均值而不是中位数?

出于某种愚蠢的原因,我需要创建一个箱线图,其中的中线是平均值而不是中位数。我已经检查了stackoverflow,并找到了添加平均线的示例,但并不完全是我需要的。我尝试使用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
Run Code Online (Sandbox Code Playgroud)

r ggplot2

4
推荐指数
2
解决办法
6414
查看次数

标签 统计

ggplot2 ×1

r ×1