0

我有一个结构如下的数据框:

> str(mydata12)
'data.frame':   228459 obs. of  2 variables:
 $ intron_length: num  0.787 0.799 2.311 2.396 1.77 ...
 $ intron_type  : Factor w/ 3 levels "All_intron","All_retained_intron",..: 1 1 1 1 1 1 1 1 1 1 ...

我已经根据这个数据框绘制了一个累积密度图:

p <- ggplot(mydata12, aes(x = intron_length, color=intron_type)) + geom_step(aes(y=..y..),stat="ecdf")

在此处输入图像描述

现在我想通过在 3 个组中添加 p 值来进行比较:

> compare_means(intron_length~intron_type, data = mydata12)
> my_comparisons <- list(c("All_intron", "All_retained_intron"), c("All_intron", "dynamic_intron"), c("All_retained_intron", "dynamic_intron"))
> p + stat_compare_means(comparisons = my_comparisons)
Error in f(...) : 
  Can only handle data with groups that are plotted on the x-axis

我想我需要在 x 轴上设置一个值来进行比较,我的问题是如何设置 x 轴值并添加 p 值?

谢谢,

4

1 回答 1

1

你不能在你拥有的东西之上叠加你想要的东西,它们是非常不同的比例和轴,但你可以做到这一点(我编造了数据,因为你没有提供......

  library(ggpubr)
#> Loading required package: ggplot2
  library(ggplot2)
  # Pairwise comparisons: Specify the comparisons you want
  my_comparisons <- list(c("All_intron", "All_retained_intron"), c("All_intron", "dynamic_intron"), c("All_retained_intron", "dynamic_intron"))
  ggboxplot(mydata12, x = "intron_type", y = "intron_length",
            color = "intron_type", palette = "npg")+
    # Add pairwise comparisons p-value
    stat_compare_means(comparisons = my_comparisons, label.y = c(1.2, 1.3, 1.4))+
    stat_compare_means(label.y = 1.5)     # Add global Anova p-value  

mydata12 <- data.frame(intron_length = runif(1000, min = 0, max = 1), 
                       intron_type = sample(c("All_intron", "All_retained_intron" , "dynamic_intron","All_retained_intron"), size = 1000, replace = TRUE))


于 2020-07-01T23:00:34.703 回答