数据格式要求模板
读取数据并计算相关性
library(tidyverse)raw_data<-read_csv("data/20231110/Source data/Fig2c&d/environment.csv") %>% select(-c(1,2,3))
corrmatrix <- cor(raw_data, method = "spearman")corrmatrix
res1 <-corrplot::cor.mtest(corrmatrix, conf.level= .95)res1$pres1$lowCIres1$uppCI
绘制相关性分析热图
col3 <- grDevices::colorRampPalette(c("#2082DD", "white", "#FF3F3F")) col3corrplot::corrplot.mixed(corr=corrmatrix, lower="number", upper="circle", diag="u", upper.col =col3(20), lower.col = col3(20), number.cex=0.9, p.mat= res1$p, sig.level= 0.05, bg = "white", is.corr = TRUE, outline = FALSE, mar = c(0,0,3,0), addCoef.col = NULL, addCoefasPercent = FALSE, order = c("original"), rect.col = "black", rect.lwd = 1, tl.cex = 1.2, tl.col = "black", tl.offset = 0.4, tl.srt = 90, cl.cex = 1.1, cl.ratio = 0.2, tl.pos="lt", cl.offset = 0.5 )title(main="Correlation coefficient of 19 environmental variables",cex.main=2.1)