我尝试使用ggpubr在我的图上显示kruskal-wallis p值,但我得到了错误消息:
Computation failed in `stat_compare_means()`:
Problem with `mutate()` input `p`.
x all observations are in the same group下面是我的代码:
library(tidyverse)
library(nortest)
library(ggpubr)
cbPalette <- c("#999999", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7")
df <- read.csv("30C static met opt_1.txt", header=TRUE, sep="\t")
my_comparisons <- list( c("465 + DMSO", "465 + Rad"), c("466 + DMSO", "466 + Rad"), c("1572", "1572 + 20 µM Met"), c("1572", "1572 + 30 µM Met"), c("1572", "1572 + 40 µM Met"), c("1572", "1572 + 50 µM Met"))
plot <- ggplot(data = df, aes(x = as.factor(Strain), y = as.numeric(OD), fill = Strain)) +
geom_boxplot(outlier.size = 0.5, fatten = 1) +
geom_dotplot(binaxis='y', stackdir='center', dotsize = 0.5) +
discrete_scale(aes(x = "Strain", y = "OD"), "OD", palette = cbPalette) +
theme_light() +
theme(panel.grid.major.x = element_blank()) +
labs(x = "Strain and drug") +
scale_y_continuous(limits = c(0.5, 2)) +
scale_x_discrete(limits = c("465 + DMSO", "465 + Rad", "466 + DMSO", "466 + Rad", "1572", "1572 + 20 µM Met", "1572 + 30 µM Met", "1572 + 40 µM Met", "1572 + 50 µM Met")) +
ylab(expression(paste(OD[595]))) +
theme(legend.position = "none", axis.text.x = element_text(angle = 45, vjust = 0.5, size = 8)) +
stat_compare_means(comparisons = my_comparisons, label = "p.adj", size = 3, step.increase = 0.15) +
stat_compare_means()
plot这给了我这个图和上面的错误消息。

这肯定是第二个stat_compare_means()导致的问题。但是我还没有在代码中使用mutate()。这个ggpubr是在幕后工作的吗?
我的数据如下所示:
head(df)
Strain OD
1 465 + DMSO 1.3458
2 465 + DMSO 1.3514
3 465 + DMSO 1.3685
4 465 + DMSO 1.3661
5 465 + DMSO 1.3991
6 465 + DMSO 1.3922发布于 2021-07-23 03:36:55
我遇到了同样的问题,并发现只有在代码中使用scale_x_discrete()时才会出现错误。没有它,它运行得很好。
我在绘制图表之前对样本进行了排序,修复了这个问题:
df$Column_name <- factor(df$Column_name, levels = c("x", "y", "z"))也许你可以试试:
my_sorted_list <- factor(c("465 + DMSO", "465 + Rad", "466 + DMSO", "466 + Rad", "1572", "1572 + 20 µM Met", "1572 + 30 µM Met", "1572 + 40 µM Met", "1572 + 50 µM Met"))
scale_x_discrete(limits = my_sorted_list)https://stackoverflow.com/questions/67510563
复制相似问题