1

我有箱线图,我想为两个因素的 4 个比较添加 pvalues。

这是数据集:

dput(CauloQ_datMannot)
structure(list(V1 = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 
3L, 3L, 
3L, 4L, 4L, 4L), .Label = c("B", "BF", "BFi ", "Bi"), 
class = "factor"), 
variable = structure(c(1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 
1L, 2L, 3L), .Label = c("V2", "V3", "V4"), class = "factor"), 
value = c(0.00051, 0.00055, 0.00056, 0.00074, 0.00079, 0.00083, 
0.00093, 0.00082, 0.00073, 0.0011, 0.00113, 0.00098), 
Location = structure(c(1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "Root", class = "factor"), 
Bean = structure(c(1L, 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, 1L, 2L, 2L, 2L), .Label = c("M+", 
"M-"), class = "factor"), Insect = structure(c(2L, 2L, 2L, 
2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("Insect", 
"NI"), class = "factor")), .Names = c("V1", "variable", "value", 
"Location", "Bean", "Fungi", "Insect"), row.names = c(NA, -12L
), class = "data.frame")

这是我目前的图表:

ggplot(CauloQ_datMannot,aes(x=Insect,y=value,fill=Fungi))+geom_boxplot()+
  guides(fill=guide_legend("Metarhizium")) +
  ggtitle("Caulobacter qPCR")+
  scale_x_discrete(labels= c("I+","I-","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))

我已经安装了 ggpubr,并阅读了 compare_stat_means,但不知道如何进行涉及这两个因素的比较。那就是我想要4个pvalues

M+/I+ 对比 M-/I+,M+/I- 对比 M-/I-,I+/M+ 对比 I-/M+,以及 I+/M- 对比 I-/M-

任何帮助表示赞赏。谢谢

> 太好了。现在感谢 Jimbou,我有以下情节。

 d %>%    unite(groups, Insect, Fungi, remove = F) %>%   
 {ggplot(.,aes(groups, value, fill= Fungi)) + 
       geom_boxplot() +    #    ggbeeswarm::geom_beeswarm()+
       ggsignif::geom_signif(comparisons =  combn(sort(unique(.$groups)),2,  simplify = F),
                             step_increase = 0.1,test='t.test')}

在此处输入图像描述

但是,我想重新订购这些盒子,即。首先是所有 I+ (其中首先是 M+)。我尝试重新排序级别,然后手动排列行,但都不起作用。

任何帮助表示赞赏

d$Insect<-factor(d$Insect,levels(d$Insect)[c(2,1)])
d$Fungi<-factor(d$Fungi,levels(d$Fungi)[c(2,1)])
4

1 回答 1

2

我建议在 x 轴上使用定义明确的组。那你可以试试

library(tidyverse)
library(ggsignif)
library(ggbeeswarm)
d %>% 
  unite(groups, Insect, Fungi, remove = F) %>% 
  {ggplot(.,aes(groups, value, fill= Fungi)) + 
   geom_boxplot() + 
   ggbeeswarm::geom_beeswarm()+
    ggsignif::geom_signif(comparisons =  combn(sort(unique(.$groups)), 2, simplify = F),
                          step_increase = 0.1)}

在此处输入图像描述

于 2019-01-11T12:24:36.323 回答