第一步安裝:
install.packages("pheatmap") #安裝pheatmap包
install.packages("RColorBrewer") #安裝RColorBrewer包
library(pheatmap) #加載pheatmap包
library(RColorBrewer) #加載RColorBrewer包
這里稍微給大家介紹一下RColorBrewer
包:
RColorBrewer is an R package that allows users to create colourful graphs with pre-made color palettes.
為什么要使用它,是因?yàn)樗G麗及豐富的配色深深的把小編吸引住了刁愿,這么好的東西一定要分享給大家虹蓄。他有三個(gè)配色诸狭。大家可以根據(jù)情況使用屎勘。
image
image
image
第二步讀取數(shù)據(jù):
首先我們來(lái)看一下數(shù)據(jù)的格式娃承,第一行為樣品名稱(chēng)予弧,第一列為基因名稱(chēng)矮男。
image
fitness <- read.delim("C:/Users/dell/Desktop/fitness.txt", row.names = 1) #讀取數(shù)據(jù)
id <- read.delim("C:/Users/dell/Desktop/id.tmp") #讀取需要畫(huà)圖的基因
fit.sel <- fitness[which(rownames(fitness) %in% id$ID), ] #提取需要畫(huà)圖的數(shù)據(jù)并保存
第三步查看數(shù)據(jù)分布:
summary(fit.sel) #查看數(shù)據(jù)最大值最小值設(shè)置scale范圍
第四步畫(huà)圖:
bk = unique(c(seq(-5, 0, length=100), seq(0, 2, length=100))) #scale范圍
col = c(colorRampPalette(rev(brewer.pal(11, "RdYlBu")))(200)) #顏色選取RdYlBu
pheatmap(fit.sel, color = col, breaks = bk, show_rownames = T, clustering_method = "ward.D2")```
最后查看結(jié)果:
image
最后總結(jié)一下常用參數(shù)的設(shè)置:
treeheight_row 設(shè)置row方向的聚類(lèi)樹(shù)高
treeheight_col 設(shè)置col方向的聚類(lèi)樹(shù)高
cellheight 表示每個(gè)單元格的高度
cellwidth 表示每個(gè)單元格的寬度
display_numbers 表示是否將數(shù)值顯示在熱圖的格子中(T/F)蟆盐。
fontsize 表示熱圖中字體顯示的大小
number_color 設(shè)置顯示內(nèi)容的顏色
pheatmap(fit.sel, cellheight=9, cellwidth=18, treeheight_row=100, treeheight_col=18,
color = col, breaks = bk, show_rownames = T, display_numbers=T,
number_color="black", fontsize=6, clustering_method = "ward.D2")
這樣運(yùn)行的結(jié)果如下:
image
歡迎關(guān)注公眾號(hào):"生物信息學(xué)"