## correlation heatmap
### 應用場景
可以同時展示多個變量之間的相關關系,比如,同時展示10個基因直接的相關系數
### correlation plot
```R
library(ggcorrplot)
# 準備數據
# 構建相關表達矩陣
get_lower_tri<-function(cormat){
cormat[upper.tri(cormat)] <- NA
return(cormat)
}
# Get upper triangle of the correlation matrix
get_upper_tri <- function(cormat){
cormat[lower.tri(cormat)]<- NA
return(cormat)
}
# Reorder the correlation matrix
reorder_cormat <- function(cormat){
# Use correlation between variables as distance
dd <- as.dist((1-cormat)/2)
hc <- hclust(dd)
cormat <-cormat[hc$order, hc$order]
}
# 利用前面兩節中差異表達數據,選取10個基因的數據做展示
rt_cor <- t(rt_ht[20:30, ])
cormat <- round(cor(rt_cor), 2)
```
> cormat數據結構如下

```R
svg(file = 'heatmap9.svg', width = 10, height = 6)
ggcorrplot(cormat)
dev.off()
# 可以改變下顏色
svg(file = 'heatmap10.svg', width = 10, height = 6)
ggcorrplot(cormat, hc.order = TRUE,
outline.col = "white",
colors = c("#6D9EC1", "white", "#E46726"))
dev.off()
# 可以按照相關系數排個序
svg(file = 'heatmap11.svg', width = 10, height = 6)
ggcorrplot(cormat, hc.order = TRUE, outline.col = "white")
dev.off()
# 可以展示upper或者lower
# 設置type參數
svg(file = 'heatmap12.svg', width = 10, height = 6)
ggcorrplot(cormat, hc.order = TRUE, outline.col = "white", type = "lower")
dev.off()
# 可以加上相關系數的值
# lab = TRUE
svg(file = 'heatmap12.svg', width = 10, height = 6)
ggcorrplot(cormat, hc.order = TRUE, type = "lower", lab = TRUE)
dev.off()
# 也可以換種展示方式
# method = "circle"
svg(file = 'heatmap14.svg', width = 10, height = 6)
ggcorrplot(cormat, hc.order = TRUE, type = "lower",
method = "circle")
dev.off()
```



- 智匯醫圈
- 第一章 前言
- 1.1 簡介
- 1.2 制作該教程的目的
- 1.3 學習該教程需要掌握的基礎知識
- 1.4 該教程適用人群
- 第二章 散點圖(scatter plot)
- 2.1 基本的散點圖
- 2.2 3D 散點圖
- 第三章 線圖(line plot)
- 3.1 基本的線圖
- 第四章 箱型圖(boxplot)
- 4.1 基本的箱型圖
- 4.2 圖形參數調整
- 4.3 多分組箱型圖
- 4.4 小提琴圖
- 第五章 密度圖(density plot)
- 5.1 基本的密度圖
- 第六章 熱圖(Heatmap)
- 6.1 基本的熱圖
- 6.2 ggplot2 heatmap
- 6.3 相關性熱圖
- 第七章 主成分分析(PCA)
- 7.1 2D PCA
- 7.2 3D PCA
- 第八章 ROC 曲線
- 8.1 基本的 ROC 曲線
- 第九章 生存分析(KM plot)
- 9.1 基本的生存分析
- 第十章 KEGG 和 GO 分析
- 10.1 KEGG 分析
- 10.2 GO 分析
- 第十一章 Circular plot
- 11.1 基本的 Circular plot
- 附錄 下載數據