欢迎关注R语言数据分析指南
❝最近在群里看到一张图,其本质仍然是相关性热图作者在图形布局上做了一些细微的改动使得整体看来有些许特别之处;下面小编就来复现一下,数据为自己构建仅供参考❞
原图
论文
❝Environmental DNA metabarcoding reveals the influence of human activities on microeukaryotic plankton along the Chinese coastline ❞
复现结果
加载R包
代码语言:javascript复制library(tidyverse)
library(linkET)
library(RColorBrewer)
library(ggtext)
library(magrittr)
library(psych)
library(reshape)
library(cowplot)
导入数据
代码语言:javascript复制table1 <- read.delim("env.xls",header =T,sep="t",row.names = 1,check.names = F)
table2 <- read.delim("genus.xls",header =T,sep="t",row.names = 1,check.names = F) %>%
t() %>% as.data.frame()
数据整合
代码语言:javascript复制❝此处跟以往一样还是进行相关性分析最终将数据整合 ❞
pp <- corr.test(table1,table2,method="pearson",adjust = "fdr")
cor <- pp$r
pvalue <- pp$p
df <- melt(cor) %>% mutate(pvalue=melt(pvalue)[,3],
p_signif=symnum(pvalue, corr = FALSE, na = FALSE,
cutpoints = c(0, 0.001, 0.01, 0.05, 0.1, 1),
symbols = c("***", "**", "*", "", " "))) %>%
set_colnames(c("env","genus","r","p","p_signif"))
# 整合分组文件
cordata <- df %>% left_join(.,read_tsv('annotation.xls'),by=c("genus")) %>%
select(group,env:p,-genus) %>%
set_colnames(c("spc","env","r","p")) %>%
mutate(rd = cut(r, breaks = c(-Inf, 0, 0.4, Inf),
labels = c("< 0", "0 - 0.4", ">= 0.4")),
pd = cut(p, breaks = c(-Inf, 0.05, Inf),
labels = c("< 0.05",">= 0.05")))