R-ggplot-在图上绘制p值

R-ggplot-在图上绘制p值,r,ggplot2,graph,p-value,R,Ggplot2,Graph,P Value,在R中使用ggplot时,我有一个关于小提琴图中p值绘图的问题。我有一个数据框,其中包含按组排序的值:1000/2000/3000/../n 我根据数据帧绘制小提琴图(见下面的示例) 我的问题是最后一个值等于数据帧的长度。在某些情况下,在另一个数据帧中可以是14470,也可以是16043或13789 我想通过比较小提琴2乘2在我的图上绘制p值(wilcoxon检验) 我所做的: my_comparisons_1000 <- list \ (c("1000", "2000"),c("200

在R中使用ggplot时,我有一个关于小提琴图中p值绘图的问题。我有一个数据框,其中包含按组排序的值:1000/2000/3000/../n

我根据数据帧绘制小提琴图(见下面的示例)

我的问题是最后一个值等于数据帧的长度。在某些情况下,在另一个数据帧中可以是14470,也可以是16043或13789

我想通过比较小提琴2乘2在我的图上绘制p值(wilcoxon检验)

我所做的:

my_comparisons_1000 <- list \
(c("1000", "2000"),c("2000", "3000"),\
c("3000", "4000"),c("4000","5000"),\
c("5000","6000"),c("6000","7000"),\
c("7000","8000"),c("8000","9000"),\
c("9000","10000"),c("10000","11000"),\
c("11000","12000"),c("12000","13000"),\
c("13000","14000"))

fig_1000<-ggplot(violin, aes(x=range_1000, y=mean_region))+
    geom_violin(scale = "width",adjust = .5,fill='#A4A4A4', color="darkred")+
    geom_boxplot(width=0.1,outlier.shape = NA) + theme_minimal()+
    scale_x_discrete(labels=c(seq(1000,length(violin[,1]),by=1000), length(violin[,1])))+
    stat_summary(fun.y=mean, geom="point",size=1,color="red",aes(shape="Mean")) +

    stat_compare_means(comparisons = my_comparisons_1000,label.y = 14)+ # Add pairwise comparisons p-value

    theme(axis.text.x = element_text(angle = 90, hjust = 1))+
    guides(colour=guide_legend(order=1), shape=guide_legend(title=NULL, order=2)))
my_\u\u 1000类似的东西

library(tidyverse)
library(ggpubr)
tidyiris <- iris %>% gather(key, value, -Species)
num_pairs <- length(unique(tidyiris$key)) - 1
my_comparisons <- map(seq(1, num_pairs, 1), ~c(.x, .x+1))
ggplot(tidyiris, aes(key, value)) + geom_violin() + 
  stat_compare_means(comparisons = my_comparisons)
库(tidyverse)
图书馆(ggpubr)
tidyiris%聚集(关键字、值、种类)

谢谢,这很有效。但是列表在14000处结束,所以我不能得到14000 et 14470的最后一个p-val,
range_1000
代表什么?有一个滴答声的值是这样的一个特定值,这似乎很奇怪。例如,将其与直方图进行比较。不管数据集中的最高值是多少,最后一个存储单元都以一个整数结束。范围是我的数据框中的一列。前1000个百值的tpm_范围=1000:2000=2000,我的长度数据帧等于14470,所以:值13000:14000=14000 14:14470=15000,然后,我根据tpm_范围绘制我的violon图,它有几个violion图,就像我的例子中我如何得到tmp_范围:vionior$tpm_range_1000=rep(seq(1000,15000,by=1000),each=1000,length.out=length(小提琴[1])很难理解你在做什么,但正如我所说的,x轴似乎有问题。