Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 统计比较多组的平均值_R_Ggplot2_Ggpubr - Fatal编程技术网

R 统计比较多组的平均值

R 统计比较多组的平均值,r,ggplot2,ggpubr,R,Ggplot2,Ggpubr,我需要一些关于统计、比较和多组的帮助 以下是我的数据 > head(df_annot) Row.names Diversity_sh Diversity_si Evenness Chao1 Location Bean Fungi Insect 1 R-B1 1.314181 0.6040213 0.3053349 91.00000 Root Bean M- NI 2 R-B2 1.323718 0.61176

我需要一些关于统计、比较和多组的帮助

以下是我的数据

> head(df_annot)
  Row.names Diversity_sh Diversity_si  Evenness    Chao1 Location Bean Fungi Insect
1      R-B1     1.314181    0.6040213 0.3053349 91.00000     Root Bean    M-     NI
2      R-B2     1.323718    0.6117602 0.3075507 77.43750     Root Bean    M-     NI
3      R-B3     1.249950    0.5737293 0.2877545 81.50000     Root Bean    M-     NI
4    R-BF-1     1.177111    0.5414276 0.2693958 92.33333     Root Bean    M+     NI
5    R-BF-2     1.191254    0.5252688 0.2742420 79.54545     Root Bean    M+     NI
6    R-BF-3     1.397233    0.6285945 0.3179540 85.50000     Root Bean    M+     NI
这是一张图表,我希望所有的比较都贴上标签

下面是一些代码。我知道我的比较不正确,但我不知道从哪里开始这两组。我想比较M+/昆虫和M+/昆虫,以及M+/昆虫和M+/NI等等,都是双向比较。任何建议都很好。谢谢

my_comparisons<- list( c("M+", "M-"), c("Insect", "NI"))
  ggplot(df_annot,aes_string(x="Insect",y=index,fill="Fungi"))+
    geom_boxplot(alpha=0.8)+
    geom_point(aes(fill=Fungi),size = 3, shape = 21,position = position_jitterdodge(jitter.width = 0.02,jitter.height = 0))+
    stat_compare_means(comparison=my_comparisons,label="p.format",method="wilcox.test")+
    #ggtitle(df_name)+
    ylab(paste(index))+
    xlab("")+
    #    scale_x_discrete(labels= c("M+","M-","soil alone"))+
    theme(plot.title = element_text(size = 18, face = "bold"))+
    theme(axis.text=element_text(size=14),
          axis.title=element_text(size=14)) + 
    theme(legend.text=element_text(size=14),
          legend.title=element_text(size=14)) +
    theme(strip.text.x = element_text(size = 14))


dput(df_annot)
structure(list(Row.names = structure(c("R-B1", "R-B2", "R-B3", 
"R-BF-1", "R-BF-2", "R-BF-3", "R-BFi-1", "R-BFi-2", "R-Bi-1", 
"R-Bi-2", "R-Bi-3"), class = "AsIs"), Diversity_sh = c(1.31418133185869, 
1.32371839350534, 1.24994951615418, 1.17711111336449, 1.19125374868316, 
1.39723272927515, 1.34145146126423, 1.21674449259962, 1.20721660188555, 
1.17245529262564, 1.20912937911657), Diversity_si = c(0.604021268328531, 
0.611760247980402, 0.573729285531772, 0.541427625516077, 0.525268755766239, 
0.628594506768001, 0.597250229879166, 0.554646956896473, 0.548992316400345, 
0.531291238688503, 0.583806537719818), Evenness = c(0.305334910927276, 
0.307550737463383, 0.287754490536268, 0.269395848882803, 0.274241968272787, 
0.317954009728278, 0.305260435164649, 0.276882141486585, 0.273949061455415, 
0.269914321375221, 0.275929262855007), Chao1 = c(91, 77.4375, 
81.5, 92.3333333333333, 79.5454545454545, 85.5, 87.5, 90.5454545454545, 
89.3333333333333, 88.6666666666667, 88.0769230769231), Location = structure(c(1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("Root", "Rhizospheric Soil"
), class = "factor"), Bean = structure(c(1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L), .Label = "Bean", class = "factor"), 
    Fungi = structure(c(2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 
    2L), .Label = c("M+", "M-"), class = "factor"), Insect = structure(c(2L, 
    2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L), .Label = c("Insect", 
    "NI"), class = "factor")), row.names = c(NA, -11L), class = "data.frame")
my\u comparations
facet\u wrap()
可能会对您有所帮助

编辑

好的,这里有一个不太优雅的解决方案,没有刻面

创建包含昆虫信息和真菌状态的新变量:

df_annot$var <- paste(df_annot$Insect,df_annot$Fungi, sep = "_" )


你可能想取更好的名字等等。但这可能是您想要的。

谢谢,但我希望实现这一点,而不涉及面,因为我想进行所有比较。我编辑了答案以回应您的评论。我希望有帮助
df_annot$var <- paste(df_annot$Insect,df_annot$Fungi, sep = "_" )
my_comparisons <- rev(list(c("Insect_M-","Insect_M+"),c("NI_M-","Insect_M-"),c("NI_M+","Insect_M-"),
                       c("Insect_M+", "NI_M-"), c("Insect_M+", "NI_M+"), c("NI_M-","NI_M+")))

ggplot(df_annot,aes_string(x="var",y="Evenness",fill="Fungi"))+
  geom_boxplot(alpha=0.8)+
  geom_point(aes(fill=Fungi),size = 3, shape = 21,position = position_jitterdodge(jitter.width = 0.02,jitter.height = 0))+
  stat_compare_means(comparison=my_comparisons,label="p.format",method="wilcox.test")+
  #ggtitle(df_name)+
  ylab(paste("Evenness"))+
  xlab("")+
  #    scale_x_discrete(labels= c("M+","M-","soil alone"))+
  theme(plot.title = element_text(size = 18, face = "bold"))+
  theme(axis.text=element_text(size=14),
        axis.title=element_text(size=14)) + 
  theme(legend.text=element_text(size=14),
        legend.title=element_text(size=14)) +
  theme(strip.text.x = element_text(size = 14))