相关性热图

2021-10-10

教程:https://www.jianshu.com/p/a4de0e3f44f5

options (warn = -1)
rm(list = ls())
gc()
##          used (Mb) gc trigger (Mb) max used (Mb)
## Ncells 431666 23.1     911465 48.7   643731 34.4
## Vcells 788655  6.1    8388608 64.0  1762629 13.5
setwd("D:/R/R-4.0.5/bin/project_writing/LIM/C_heatmap")
dataPath <- "D:/R/R-4.0.5/bin/project_writing/LIM/data"
figurePath <- "D:/R/R-4.0.5/bin/project_writing/LIM/figure"
glist <- c("ISL1","ISL2","LHX1","LHX2","LHX3","LHX4","LHX5","LHX6","LHX8","LHX9","LMX1A","LMX1B")

library(ggplot2)
library(ggthemes)
library(corrplot)
## corrplot 0.90 loaded
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v tibble  3.1.4     v dplyr   1.0.7
## v tidyr   1.1.4     v stringr 1.4.0
## v readr   2.0.2     v forcats 0.5.1
## v purrr   0.3.4
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(readr)
library(ggsci)
library(scales)
## 
## 载入程辑包:'scales'
## The following object is masked from 'package:purrr':
## 
##     discard
## The following object is masked from 'package:readr':
## 
##     col_factor
library(ggcorrplot)

相关性计算

exprP <- read_csv("D:/R/R-4.0.5/bin/project_writing/LIM/TCGA_HNSC_mRNA_count_paired_43vs43.csv") %>% as.data.frame()
## New names:
## * `` -> ...1
## Rows: 34125 Columns: 87
## -- Column specification --------------------------------------------------------
## Delimiter: ","
## chr  (1): ...1
## dbl (86): TCGA-CV-6943-01A, TCGA-CV-6959-01A, TCGA-CV-7438-11A, TCGA-CV-7242...
## 
## i Use `spec()` to retrieve the full column specification for this data.
## i Specify the column types or set `show_col_types = FALSE` to quiet this message.
rownames(exprP) <- exprP[,1]
exprP <- exprP[,-1]
exprP <- exprP[glist,]
exprP[1:4,1:4]
##      TCGA-CV-6943-01A TCGA-CV-6959-01A TCGA-CV-7438-11A TCGA-CV-7242-11A
## ISL1         5.000000         6.000000         6.044394         6.857981
## ISL2         6.442943         6.870365         4.087463         2.321928
## LHX1         7.774787         9.612868         3.169925         1.000000
## LHX2         5.247928         5.209453         2.807355         1.000000
## 12gene 86sample

Cor <- round(cor(t(exprP)),3)
Pmat <- round(cor_pmat(t(exprP)),3) # 计算相关显著性P值矩阵

pal_npg('nrc')(4)
## [1] "#E64B35FF" "#4DBBD5FF" "#00A087FF" "#3C5488FF"
show_col(pal_npg('nrc',alpha = 1)(4))

ggcorrplot(Cor,method = "circle",
           hc.order = T,hc.method = "ward.D",
           outline.color = 'white',
           ggtheme = theme_bw(),
           type = "upper",
           lab = TRUE,lab_size = 2,
           colors = c("#4DBBD5FF","white","#E64B35FF"),
           p.mat = Pmat,insig = "pch",
           tl.cex = 8)