【R語言】熱圖繪製-heatmap+gplots配色方案
前面給大家介紹瞭如何使用R自帶的heatmap函式+R自帶的配色方案來繪製熱圖
☞【R語言】熱圖繪製-heatmap函式
☞R語言中的顏色(一)-自帶的調色盤
今天我們接著來聊
heatmap
這個函式繪製熱圖,這次我們使用
gplots
這個R包裡面的配色方案
☞R語言中的顏色(二)-gplots包
首先我們還是先讀取需要的資料,這裡用到的資料跟【R語言】熱圖繪製-heatmap函式用到的資料是一樣的
#
讀取所有miRNA的表達矩陣
expr
=
read
。
table
(
“miRNA_expr。txt”,header=T,row。names=1,sep=“\t”)
#
讀取差異表達分析結果
#
差異表達分析可以參考https
://
ke
。
。
com
/
course
/
package
/
37513
deg
=
read
。
table
(
“MIR_DEG_fc_2。5_pval_0。01。txt”,header=T,row。names = 1,sep=“\t”)
#
設定樣本型別
type
=
factor
(
rep
(
c
(
“CR”,“CC”),each=3))
#
提取差異表達miRNA的名字
miRNA
=
rownames
(
deg
)
#
提取差異表達miRNA對應的表達矩陣
data
=
as
。
matrix
(
expr
[
miRNA
,])
接下來我們需要安裝gplots這個R包,因為需要用到裡面的配色方案
#
如果沒有安裝gplots這個包
,
需要先去掉下一行中的
#,
再執行進行安裝
#
install
。
packages
(
“gplots”)
#
載入gplots包
library
(
gplots
)
最後我們就可以來利用heatmap和gplots裡面的配色方案來繪製
火山圖
了
1。採用gplots包中的redblue配色方案,藍色高表達,紅色低表達
heatmap(data, cexCol = 1,scale=“row”,col = redblue(100))
2。採用gplots包中的bluered配色方案,紅色高表達,藍色低表達
heatmap(data, cexCol = 1,scale=“row”,col = bluered(100))
3。採用gplots包中的redgreen配色方案,綠色高表達,紅低表達
heatmap(data, cexCol = 1,scale=“row”,col = redgreen(100))
4。採用gplots包中的greenred配色方案,紅色高表達,綠低表達
heatmap(data, cexCol = 1,scale=“row”,col = greenred(100))
5。採用gplots包中的colorpanel配色方案,由綠到紅的漸變,綠低表達,紅色高表達
heatmap(data, cexCol = 1,scale=“row”,col = colorpanel(100,low=“green”,high=“red”))
6。採用gplots包中的colorpanel配色方案,由綠到黃再到紅的漸變,綠低表達,紅色高表達,黃色為中間值
heatmap(data, cexCol = 1,scale=“row”,col = colorpanel(100,low=“green”,mid = “yellow”, high=“red”))
本文中使用的表達矩陣來自GEO公共資料庫
https://www。
ncbi。nlm。nih。gov/geo/qu
ery/acc。cgi?acc=GSE82236
關於GEO資料庫檢索和差異表達分析可以參考
☞基於GEO公共資料庫的資料探勘
獲取文中使用的原始資料
參考資料:
☞【R語言】熱圖繪製-heatmap函式
☞R語言中的顏色(一)-自帶的調色盤
☞R語言中的顏色(二)-gplots包
☞ 超詳細的熱圖繪製教程(5000餘字),真正的保姆級教程
☞ R語言繪製基因表達熱圖(簡易版)
☞ 一個R函式搞定風險評估散點圖,熱圖
☞ R繪製甲基化和表達譜聯合分析熱圖