如何在 R 中的 ggplot2 中绘制组均值的平均值?

How to plot mean of group means in ggplot2 in R?

我有以下数据(dat)

V  W  X  Y  Z
1  2  3  4  5
2  2  3  4  5
3  2  3  4  5
4  2  3  4  5

我想绘制一条 线 与组均值的平均值 例如。在上面的数据集中,所有组的总体平均值为 3.3。因此,连同组均值图,我需要一条包含组均值平均值的线。

简单分组方式的代码如下:

dat1 <- gather(dat)#long format
ggplot(data = dat1, aes(x = key, y = value)) + 
  stat_summary(fun.data = "mean_cl_normal", colour = "red", size  = 1)

关于如何在不计算组均值和 CI 外部然后调用 ggplot2 中的值的情况下实现这一点的任何想法?

也许这有帮助

library(tidyr)
library(dplyr)
library(ggplot2)
dat %>% 
   mutate(all = mean(unlist(.)) + rnorm(n())) %>%
    gather() %>%
    ggplot(., aes(x=key, y=value)) +
          stat_summary(fun.data = "mean_cl_normal", colour = "red", size  = 1)