首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >`stat_compare_means()`计算失败:输入`p`时出现问题` `mutate()`。X所有观察值都在同一组中

`stat_compare_means()`计算失败:输入`p`时出现问题` `mutate()`。X所有观察值都在同一组中
EN

Stack Overflow用户
提问于 2021-05-13 04:24:08
回答 1查看 265关注 0票数 0

我尝试使用ggpubr在我的图上显示kruskal-wallis p值,但我得到了错误消息:

代码语言:javascript
复制
Computation failed in `stat_compare_means()`:
Problem with `mutate()` input `p`.
x all observations are in the same group

下面是我的代码:

代码语言:javascript
复制
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是在幕后工作的吗?

我的数据如下所示:

代码语言:javascript
复制
    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
EN

回答 1

Stack Overflow用户

发布于 2021-07-23 03:36:55

我遇到了同样的问题,并发现只有在代码中使用scale_x_discrete()时才会出现错误。没有它,它运行得很好。

我在绘制图表之前对样本进行了排序,修复了这个问题:

代码语言:javascript
复制
df$Column_name <- factor(df$Column_name, levels = c("x", "y", "z"))

也许你可以试试:

代码语言:javascript
复制
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)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67510563

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档