美文网首页基本图形绘制
配对数据wilcox.test检验及可视化

配对数据wilcox.test检验及可视化

作者: bioYIYI | 来源:发表于2021-11-18 09:45 被阅读0次

用途

配对样本秩和检验及可视化(箱线图)

代码

加载包

library(plyr)
library(ggplot2)
library("ggpubr")
library(ggplot2)
library(cowplot)

第一组数据检验及画图(不单独生成图片)

Standardizing_functional<-read.table("1_shannon_Standardizing/functional/delta_shannon_patient.xls",header=T,sep="\t")
c<-Standardizing_functional$delta.H_P-Standardizing_functional$delta.H_S
ylim=max(c)+0.1
Standardizing_functional$Standardizing_functional<-c
p<-wilcox.test(Standardizing_functional$delta.H_P,Standardizing_functional$delta.H_S,paired = T)
p_Standardizing_functional<-ggplot(Standardizing_functional, aes(x="Standardizing functional", y=Standardizing_functional)) + geom_boxplot(color='blue',outlier.colour="grey", outlier.shape=8, outlier.alpha=0.8,outlier.size= 0.7, width = 0.2) + guides(fill=F, color=F) +theme(panel.grid.major.x=element_blank(), axis.text.x=element_text(angle=0, hjust=0.5))  +ylab('shannon (P) - shannon (S)') +xlab('')+ annotate(geom="text", x=1.2, y=ylim, label=paste('Wilcoxon, p =',round(p$p.value,5),sep=""),colour='black', size=2)

第2/3/4/5/6组数据检验及画图

Standardizing_none_functional<-read.table("1_shannon_Standardizing/none_functional/delta_shannon_patient.xls",header=T,sep="\t")
c<-Standardizing_none_functional$delta.H_P-Standardizing_none_functional$delta.H_S
ylim=max(c)+0.1
Standardizing_none_functional$Standardizing_none_functional<-c
p<-wilcox.test(Standardizing_none_functional$delta.H_P,Standardizing_none_functional$delta.H_S,paired = T)
p_Standardizing_none_functional<-ggplot(Standardizing_none_functional, aes(x="Standardizing none_functional", y=Standardizing_none_functional)) + geom_boxplot(color='blue',outlier.colour="grey", outlier.shape=8, outlier.alpha=0.8,outlier.size= 0.7, width = 0.2) + guides(fill=F, color=F) +theme(panel.grid.major.x=element_blank(), axis.text.x=element_text(angle=0, hjust=0.5))  +ylab('shannon (P) - shannon (S)') +xlab('')+ annotate(geom="text", x=1.2, y=ylim, label=paste('Wilcoxon, p =',round(p$p.value,5),sep=""),colour='black', size=2)

all<-read.table("1_shannon_Standardizing/all/delta_shannon_patient.xls",header=T,sep="\t")
c<-all$delta.H_P-all$delta.H_S
ylim=max(c)+0.1
all$all<-c
p<-wilcox.test(all$delta.H_P,all$delta.H_S,paired = T)
p_all<-ggplot(all, aes(x="Standardizing all", y=all)) + geom_boxplot(color='blue',outlier.colour="grey", outlier.shape=8, outlier.alpha=0.8,outlier.size= 0.7, width = 0.2) + guides(fill=F, color=F) +theme(panel.grid.major.x=element_blank(), axis.text.x=element_text(angle=0, hjust=0.5))  +ylab('shannon (P) - shannon (S)') +xlab('')+ annotate(geom="text", x=1.2, y=ylim, label=paste('Wilcoxon, p =',round(p$p.value,5),sep=""),colour='black', size=2)

without_normalize_functional<-read.table("2_shannon_without_normalize/functional/delta_shannon_patient.xls",header=T,sep="\t")
c<-without_normalize_functional$delta.H_P-without_normalize_functional$delta.H_S
ylim=max(c)+0.1
without_normalize_functional$without_normalize_functional<-c
p<-wilcox.test(without_normalize_functional$delta.H_P,without_normalize_functional$delta.H_S,paired = T)
p_without_normalize_functional<-ggplot(without_normalize_functional, aes(x="NoneStandardizing functional", y=without_normalize_functional)) + geom_boxplot(color='blue',outlier.colour="grey", outlier.shape=8, outlier.alpha=0.8,outlier.size= 0.7, width = 0.2) + guides(fill=F, color=F) +theme(panel.grid.major.x=element_blank(), axis.text.x=element_text(angle=0, hjust=0.5))  +ylab('shannon (P) - shannon (S)') +xlab('')+ annotate(geom="text", x=1.2, y=ylim, label=paste('Wilcoxon, p =',round(p$p.value,5),sep=""),colour='black', size=2)

without_normalize_none_functional<-read.table("2_shannon_without_normalize/none_functional/delta_shannon_patient.xls",header=T,sep="\t")
c<-without_normalize_none_functional$delta.H_P-without_normalize_none_functional$delta.H_S
ylim=max(c)+0.1
without_normalize_none_functional$without_normalize_none_functional<-c
p<-wilcox.test(without_normalize_none_functional$delta.H_P,without_normalize_none_functional$delta.H_S,paired = T)
p_without_normalize_none_functional<-ggplot(without_normalize_none_functional, aes(x="NoneStandardizing none_functional", y=without_normalize_none_functional)) + geom_boxplot(color='blue',outlier.colour="grey", outlier.shape=8, outlier.alpha=0.8,outlier.size= 0.7, width = 0.2) + guides(fill=F, color=F) +theme(panel.grid.major.x=element_blank(), axis.text.x=element_text(angle=0, hjust=0.5))  +ylab('shannon (P) - shannon (S)') +xlab('')+ annotate(geom="text", x=1.2, y=ylim, label=paste('Wilcoxon, p =',round(p$p.value,5),sep=""),colour='black', size=2)

without_normalize_all<-read.table("2_shannon_without_normalize/all/delta_shannon_patient.xls",header=T,sep="\t")
c<-without_normalize_all$delta.H_P-without_normalize_all$delta.H_S
ylim=max(c)+0.1
without_normalize_all$without_normalize_all<-c
p<-wilcox.test(without_normalize_all$delta.H_P,without_normalize_all$delta.H_S,paired = T)
p_without_normalize_all<-ggplot(without_normalize_all, aes(x="NoneStandardizing all", y=without_normalize_all)) + geom_boxplot(color='blue',outlier.colour="grey", outlier.shape=8, outlier.alpha=0.8,outlier.size= 0.7, width = 0.2) + guides(fill=F, color=F) +theme(panel.grid.major.x=element_blank(), axis.text.x=element_text(angle=0, hjust=0.5))  +ylab('shannon (P) - shannon (S)') +xlab('')+ annotate(geom="text", x=1.2, y=ylim, label=paste('Wilcoxon, p =',round(p$p.value,5),sep=""),colour='black', size=2)

把多个图片组合到一起

方法1:

pdf("Standardizing.pdf",width=12,height=8)
g <- ggdraw() + draw_plot(p_Standardizing_functional, 0, 0.5, 0.33, 0.5) + draw_plot(p_Standardizing_none_functional, 0.33, 0.5, 0.33, 0.5) +draw_plot(p_all, 0.66, 0.5, 0.33, 0.5)+ draw_plot(p_without_normalize_functional, 0, 0, 0.33, 0.5) + draw_plot(p_without_normalize_none_functional, 0.33, 0, 0.33, 0.5) +draw_plot(p_without_normalize_all, 0.66, 0, 0.33, 0.5)
print(g)
dev.off()

方法2:

pdf("Standardizing_method2.pdf",width=12,height=8)
ggarrange(p_Standardizing_functional,p_Standardizing_none_functional,p_all,p_without_normalize_functional,p_without_normalize_none_functional,p_without_normalize_all,ncol=3,nrow=2)
dev.off()

输入数据示例

image.png

结果示例

image.png

相关文章

  • 配对数据wilcox.test检验及可视化

    用途 配对样本秩和检验及可视化(箱线图) 代码 加载包 第一组数据检验及画图(不单独生成图片) 第2/3/4/5/...

  • 配对样本检验及绘图

    1. 下载GEO数据 2. 注释及得到基因表达矩阵 3. 提取配对样本数据 5. 计算配对样本T检验及wilcox...

  • 统计-T检验和ANOVA+代码实战

    细说T检验: A 配对T检验:针对一个样本,当你有实验前和实验后的两组数据时选择配对T检验 不配对T检验推荐选择d...

  • 相关性计算与检验

    成对数据进行相关性分析可使用可视化方法及相关性检验方法:可视化方法主要通过散点图观察数据的线性关系; 而相关性检验...

  • 手把手教你快速完成配对T检验

    一、配对样本T检验 配对t检验,用于配对定量数据之间的差异对比关系。例如在两种背景情况下(有广告和无广告);样本的...

  • 配对t检验说明

    配对t检验说明 配对样本t检验是统计学中参数检验的一种有效途径,可以用来检验两组具有相关性的样本数据是否源自同均值...

  • 如何选择T检验?

    内容目录 t 检验分类配对 t 检验(非独立t检验)非配对 t 检验(独立t检验)单/双侧 t 检验选择 小结: ...

  • Mcnemar检验,Kappa检验

    1. 配对四格表的卡方检验 熟悉经典比较的都知道有配对t检验,在列联表中也有配对的列联表。与配对t检验类似,配对列...

  • t检验该怎么分析?如果选择哪种t检验?

    T检验过比较不同数据的均值,研究两组数据之间是否存在差异。可以分为三种,分别是单样本T检验、配对样本T检验、独立样...

  • 分类代码模板-python

    1、数据预处理2、拟合所需要的分类模型3、预测测试集结果4、混淆矩阵检验预测结果5、可视化训练集及模型6、可视化测...

网友评论

    本文标题:配对数据wilcox.test检验及可视化

    本文链接:https://www.haomeiwen.com/subject/uexrtrtx.html