ggcorrplot绘制相关性热图

安装包

  • conda activate wgcna
  • conda install -c conda-forge r-ggcorrplot -y
  • conda install -c conda-forge r-ggsci -y
  • # conda install -c conda-forge r-gridextra -y

颜色参考

1
2
3
4
5
6
7
8
library("reshape2")

set.seed(42)
k <- 9
x <- diag(k)
x[upper.tri(x)] <- runif(sum(1:(k - 1)), 0, 1)
x_melt <- melt(x)

相关性热图

1
2
3
4
5
6
7
8
9
10
11
12
13
library(Hmisc)
library(ggcorrplot)
library(ggsci)
library(gridExtra)
f_corrplot <- function(lc_scdata, scale=T, lab=F){
lc_cor <- rcorr(lc_scdata)
lc_cor$P[is.na(lc_cor$P)]=0
if(scale){lc_cor$r[lc_cor$r<0] <- lc_cor$r[lc_cor$r<0] - (1 + min(lc_cor$r))}
ggcorrplot(lc_cor$r, type="full",hc.order = T, lab = lab, p.mat = lc_cor$P)
}
options(repr.plot.width=8, repr.plot.height=8)
p <- f_corrplot(as.matrix(datExpr)) + scale_fill_material("cyan")
p

ggcorrplot绘制相关性热图
https://b.limour.top/1957.html
Author
Limour
Posted on
August 9, 2022
Licensed under