ggplot2:如何在facet_wrap()上使用stat_compare_means()添加p_values,其中scale = free

时间:2018-04-17 14:32:43

标签: r ggplot2 facet-wrap ggpubr

我正在尝试使用ggplot2在多个图表上添加p值,并且它运行良好(图1),直到我尝试使用scales =“free”。当我添加免费比例时,它会收到Warning messages: 1: Computation failed in stat_compare_means(: group1, p must resolve to integer column positions, not NULL

我的数据框:

    > burst.data
      Host Clade   Phage Burst.Size
1   CC9605     A S-TIP28         20
2   CC9605     A S-TIP28         25
3   CC9605     A S-TIP28         38
4   CC9605     A S-TIP28         44
5   CC9605     A S-TIP28         56
6   CC9605     A S-TIP28         56
7   CC9605     A S-TIP28         59
8   CC9605     A S-TIP28         61

没有比例的代码=免费:

ggplot(burst.data, aes(Phage, Burst.Size,fill=Clade))+
  geom_boxplot(width=0.75,outlier.size=5,size=1.5)+
  facet_wrap( ~ Host,nrow = 1)+
  stat_compare_means( )

图像: enter image description here

但当我尝试使用scale =“free”仅显示每个图的相关数据时 stat_compare_means()重新发出warnig,而不是将p值添加到图中:

> ggplot(burst.data, aes(Phage, Burst.Size,fill=Clade))+
+   geom_boxplot()+
+   facet_wrap( ~ Host,scales = "free",nrow = 1)+
+   stat_compare_means( )
Warning messages:
1: Computation failed in `stat_compare_means()`:
`group1`, `p` must resolve to integer column positions, not NULL 
2: Computation failed in `stat_compare_means()`:
`group1`, `p` must resolve to integer column positions, not NULL 
3: Computation failed in `stat_compare_means()`:
`group1`, `p` must resolve to integer column positions, not NULL 

enter image description here

0 个答案:

没有答案