# 带有显著性标记的相关性热图绘制方法

https://www.jianshu.com/p/d86ddf8fd48f

https://mp.weixin.qq.com/s/5tHE5apk2SwDmcSLYQx48Q

#psych包用于计算相关性、p值等信息

library(psych)

#pheatmap包用于绘制相关性热图

library(pheatmap)

#reshape2包用于输出数据的整合处理

library(reshape2)

#准备数据

#读取数据

plant=read.table("20200721--Plant.txt", header = T, row.names = 1)

lefse=read.table("20200721--Lefse.txt", header = T, row.names = 1)

#计算相关性

cor = corr.test(lefse, plant, method="spearman", adjust="none")

#提取相关性、p

cmt <-cor$r pmt <- cor$p

#判断显著性

if (!is.null(pmt)){

ssmt <- pmt< 0.01

pmt[ssmt] <-'**'

smt <- pmt >0.01& pmt <0.05

pmt[smt] <- '*'

pmt[!ssmt&!smt]<- ''

} else {

pmt <- F

}

#自定义颜色范围

mycol<-colorRampPalette(c("blue","white","tomato"))(800)

#可视化

pheatmap(cmt,scale = "none", cluster_row = F, cluster_col = F, border=NA, fontsize_row=8, fontsize_col=8, display_numbers = pmt, fontsize_number = 10, number_color = "white", cellwidth = 13, cellheight =13,color=mycol, filename="plant.lefse.jpg")

#结果展示

https://blog.sciencenet.cn/blog-2675068-1242946.html

## 全部精选博文导读

GMT+8, 2022-1-25 21:23

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社