R语言:Mantel Test分析与绘图

您所在的位置:网站首页 森林图怎么做相关性 R语言:Mantel Test分析与绘图

R语言:Mantel Test分析与绘图

2024-07-13 02:59| 来源: 网络整理| 查看: 265

Mantel Test 1.什么是Mantel Test2. R语言代码13. R语言代码2

1.什么是Mantel Test

  Mantel test分析对两个矩阵相关关系进行检验。可以用在生态学上,用来检验群落距离矩阵(如 Bray-Curtis distance matrix)和环境变量距离矩阵(如 pH, 温度 或者地理位置的差异矩阵)之间的相关性(Spearman、Pearson)。Mantel test的相关性系数越大,p值越小,则说明环境因子对微生物群落的影响越大。同时,mantel test的偏分析(partial Mantel test等)可排除环境因子之间自相关的干扰。   Mantel test分析结果: 在这里插入图片描述   文献参考: Structure and function of the global ocean microbiome

2. R语言代码1

  这里我使用了R内置的两个数据进行分析,并对图像进行了美化和调整。   在这里我使用的是linkET包,当然你也可以使用ggcor包,但是我不能安装这个包,所以就没有使用。

#热图+网络图展示mantel test相关性 # 加载包 # devtools::install_github("Hy4m/linkET", force = TRUE) library(linkET) library(tidyverse) library(RColorBrewer) data("varechem", package = "vegan") data("varespec", package = "vegan") head(varespec[,1:6])#rownames is samples head(varechem[,1:6])#rownames is samples dim(varespec)#24,44 dim(varechem)#24,14 mantel % dplyr::mutate(rd = cut(r, breaks = c(-Inf, 0.2, 0.4, Inf), labels = c("< 0.2", "0.2 - 0.4", ">= 0.4")), pd = cut(p, breaks = c(-Inf, 0.01, 0.05, Inf), labels = c("< 0.01", "0.01 - 0.05", ">= 0.05"))); mantel correlate(varechem) %>% qcorrplot(type = "lower", diag = T) + geom_square() + geom_couple(aes(colour = pd, size = rd), data = mantel, curvature = 0.1) + geom_mark(sep = '\n',size = 4, sig_level = c(0.05, 0.01, 0.001), sig_thres = 0.05, color = 'black', ) + scale_fill_gradientn(colours = RColorBrewer::brewer.pal(9, "RdBu")) + scale_size_manual(values = c(0.5, 1, 2)) + scale_colour_manual(values = color_pal(3)) + labs(fill = "Pearson's correlation", size = "Mantel's r value", colour = "Mantel's p value")+ theme( text = element_text(size = 14, family = "serif"), plot.title = element_text(size = 14, colour = "black", hjust = 0.5), legend.title = element_text(color = "black", size = 14), legend.text = element_text(color = "black", size = 14), axis.text.y = element_text(size = 14, color = "black", vjust = 0.5, hjust = 1, angle = 0), axis.text.x = element_text(size = 14, color = "black", vjust = 0.5, hjust = 0.5, angle = 0) )

结果展示:

在这里插入图片描述

3. R语言代码2 rm(list=ls())#好习惯,确保有干净的 R 环境 # setwd("C:/Users/Desktop/take") library(linkET) library(ggplot2) library(ggtext) library(dplyr) library(RColorBrewer) library(cols4all) library(tidyverse) data("varechem", package = "vegan") data("varespec", package = "vegan") #计算环境因子相关性系数: cor2


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3