0

我想用 pvalues 标记我的箱线图。

这是我的代码:

ggplot(df_annot,aes(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))+
  facet_wrap(~Location,scales="free" )+
  stat_compare_means(aes(group="Insect"))+
  guides(fill=guide_legend("M. robertii")) +
  scale_x_discrete(labels= c("I+","I-","soil alone"))+
  ylab(index_name)+
  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))

这是我收到的错误消息:

警告消息:
1:未知或未初始化的列:'p'。
2:计算失败stat_compare_means():缺少参数“x”,没有默认值
3:未知或未初始化的列:“p”。
4:计算失败stat_compare_means():缺少参数“x”,没有默认值

我试过aes()从主要的 ggplot 调用移动到 boxplot 调用。我尝试过不同inherit.aesstat_compare_means(). 我已经尝试过首先对根部分进行子集化并将它们分别制作,但同样的错误。

任何帮助表示赞赏。

谢谢

这是我的数据:

> dput(df_annot)
structure(list(Location = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Root", "Rhizospheric Soil"
), class = "factor"), Bean = structure(c(1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("Bean", "No 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"), index = c(2.90952191983974, 3.19997588762484, 
2.96753469534499, 2.93030877512644, 2.72220793003196, 3.09008037591454, 
2.63687890737919, 2.73583925812843, 3.06766793411045, 3.26431040286099, 
3.03361194852963, 2.9181623054061)), row.names = c("S-B1", 
"S-B2", "S-B3", "S-BF-1", "S-BF-2", "S-BF-3", "S-BFi-1", "S-BFi-2", 
"S-BFi-3", "S-Bi-1", "S-Bi-2", "S-Bi-3"), class = "data.frame")
4

1 回答 1

1

对您的错误的一种可能且简单的修复可能是使用确切的变量名称(即从变量名称中删除双引号)而不是 stat_compare_means () 中的引用变量名称(即字符),因此函数应如下所示:

stat_compare_means(aes(group=Insect))

使用 ggboxplot() 的工作示例如下:

library(ggpubr)

boxplot <- ggboxplot(ToothGrowth, x = "dose", y = "len", add = "jitter",
                             color = "supp", group="supp", palette = "jco", legend.title="Supplier")
boxplot <- boxplot + stat_compare_means(aes(group=supp), label = "p.signif", method="wilcox.test", hide.ns=T, paired=F)

print(bxp.legend)

在此处输入图像描述 上面的例子有一条警告信息,但我不知道如何改进代码以删除警告信息:

`cols` is now required.
Please use `cols = c(p)` 
于 2019-11-28T11:48:53.077 回答