初學(xué)者R語(yǔ)言:熱圖基礎(chǔ)畫(huà)法及個(gè)性化調(diào)整詳解

熱圖(Heatmap):用顏色變化直觀的表達(dá)數(shù)據(jù)之間差異的圖块攒,是對(duì)實(shí)驗(yàn)數(shù)據(jù)進(jìn)行質(zhì)制和差異數(shù)據(jù)的展現(xiàn),是數(shù)據(jù)挖掘類文章的標(biāo)配佃乘。

Rplot1.jpeg

例如上圖囱井,每個(gè)小方格表示每個(gè)基因,其顏色表示該基因表達(dá)量大小庞呕,表達(dá)量越大顏色越深(紅色為上調(diào)地啰,藍(lán)色為下調(diào))盏混。每行表示每個(gè)基因在不同樣本中的表達(dá)量情況止喷,每列表示每個(gè)樣品中所有基因的表達(dá)量情況句喜。上方樹(shù)形圖表示對(duì)來(lái)自不同實(shí)驗(yàn)分組的不同樣品的聚類分析結(jié)果

Draw heatmaps#畫(huà)熱圖

pheatmap(test)
pheatmap(test, kmeans_k = 2)#把所有行歸為兩類畫(huà)熱圖
pheatmap(test, scale = "row")#歸一化(按照行),防止因極大值使其他值的差異顯現(xiàn)不出來(lái)
pheatmap(test, color = colorRampPalette(c("navy", "white", "firebrick3"))(50))#設(shè)定圖表顏色,不設(shè)定則為默認(rèn)顏色,50為50個(gè)色塊
pheatmap(test, cluster_row = FALSE)#不按照行排序,意味遵循表格原始行的順序
pheatmap(test, legend = FALSE)#不標(biāo)注注釋信息

Show text within cells#在單元格中顯示文本

pheatmap(test, display_numbers = TRUE)#顯示每個(gè)格子具體代表的數(shù)字
pheatmap(test, display_numbers = TRUE, number_format = "\%.1e")
pheatmap(test, display_numbers = matrix(ifelse(test > 5, "*", ""), nrow(test)))#大于5的*號(hào)
pheatmap(test, cluster_row = FALSE,  legend_breaks= -1:4,)
)
legend_breaks= -1:4#只顯示注釋信息的-1到4,
legend_labels = c("0","1e-4", "1e-3", "1e-2", "1e-1", "1")#把注釋標(biāo)簽換成這幾個(gè)數(shù)字

Fix cell sizes and save to file with correct size#修復(fù)單元格大小并以正確的大小保存到文件

pheatmap(test, cellwidth = 15, cellheight = 12,main = "Example heatmap")#設(shè)定寬,高挡闰,main為設(shè)定表的表頭,也就是名字
pheatmap(test, cellwidth = 15, cellheight = 12, fontsize = 8, filename = "test.pdf")#fontsize設(shè)定字體大小,filename設(shè)定文件名

Generate annotations for rows and columns#為行和列生成注釋

annotation_col = data.frame(
  CellType = factor(rep(c("CT1", "CT2"), 5)), 
  Time = 1:5
)
rownames(annotation_col) = paste("Test", 1:10, sep = "")

annotation_row = data.frame(
  GeneClass = factor(rep(c("Path1", "Path2", "Path3"), c(10, 4, 6)))
)
rownames(annotation_row) = paste("Gene", 1:20, sep = "")

Display row and color annotations#顯示行和列注釋

pheatmap(test, annotation_col = annotation_col)#顯示列注釋
pheatmap(test, annotation_col = annotation_col, annotation_legend = FALSE)#顯示列注釋罗洗,并去掉其解說(shuō)
pheatmap(test, annotation_col = annotation_col, annotation_row = annotation_row)#顯示行注釋及列注釋

Change angle of text in the columns更改列中文本的角度

pheatmap(test, annotation_col = annotation_col, annotation_row = annotation_row, angle_col = "45")#下標(biāo)文本傾斜45角書(shū)寫(xiě)
pheatmap(test, annotation_col = annotation_col, angle_col = "0")#下標(biāo)文本水平書(shū)寫(xiě)

Specify colors指定顏色

ann_colors = list(
  Time = c("white", "firebrick"),
  CellType = c(CT1 = "#1B9E77", CT2 = "#D95F02"),
  GeneClass = c(Path1 = "#7570B3", Path2 = "#E7298A", Path3 = "#66A61E")
)

分別設(shè)定3種注釋不同的顏色

pheatmap(test, annotation_col = annotation_col, annotation_colors = ann_colors, main = "Title")
pheatmap(test, annotation_col = annotation_col, annotation_row = annotation_row, 
         annotation_colors = ann_colors)
pheatmap(test, annotation_col = annotation_col, annotation_colors = ann_colors[2]) 

把顏色顯示在圖表中

# Gaps in heatmaps
pheatmap(test, annotation_col = annotation_col, cluster_rows = FALSE, gaps_row = c(10, 14))#在第10行和14行后分開(kāi)
pheatmap(test, annotation_col = annotation_col, cluster_rows = FALSE, gaps_row = c(10, 14), 
         cutree_col = 2)#縱分為兩部分

Show custom strings as row/col names將自定義字符串顯示為行/列名稱

labels_row = c("", "", "", "", "", "", "", "", "", "", "", "", "", "", "", 
               "", "", "Il10", "Il15", "Il1b")#定義你想要的行名稱

pheatmap(test, annotation_col = annotation_col, labels_row = labels_row)#替換原來(lái)的行名稱

Specifying clustering from distance matrix從距離矩陣指定聚類

drows = dist(test, method = "minkowski")
dcols = dist(t(test), method = "minkowski")
pheatmap(test, clustering_distance_rows = drows, clustering_distance_cols = dcols)
pheatmap(test)
pheatmap(test, kmeans_k = 2)#把所有行歸為兩類畫(huà)熱圖
pheatmap(test, scale = "row")#歸一化(按照行),防止因極大值使其他值的差異顯現(xiàn)不出來(lái)
pheatmap(test, color = colorRampPalette(c("navy", "white", "firebrick3"))(50))#設(shè)定圖表顏色馏鹤,不設(shè)定則為默認(rèn)顏色,50為50個(gè)色塊
pheatmap(test, cluster_row = FALSE)#不按照行排序治力,意味遵循表格原始行的順序
pheatmap(test, legend = FALSE)#不標(biāo)注注釋信息

Show text within cells#在單元格中顯示文本

pheatmap(test, display_numbers = TRUE)#顯示每個(gè)格子具體代表的數(shù)字
pheatmap(test, display_numbers = TRUE, number_format = "\%.1e")
pheatmap(test, display_numbers = matrix(ifelse(test > 5, "*", ""), nrow(test)))#大于5的*號(hào)
pheatmap(test, cluster_row = FALSE,  legend_breaks= -1:4,)
)
马澈,#legend_breaks= -1:4#只顯示注釋信息的-1到4疑枯,
国章,#legend_labels = c("0","1e-4", "1e-3", "1e-2", "1e-1", "1")#把注釋標(biāo)簽換成這幾個(gè)數(shù)字

Fix cell sizes and save to file with correct size#修復(fù)單元格大小并以正確的大小保存到文件

pheatmap(test, cellwidth = 15, cellheight = 12,main = "Example heatmap")#設(shè)定寬四啰,高,main為設(shè)定表的表頭,也就是名字
pheatmap(test, cellwidth = 15, cellheight = 12, fontsize = 8, filename = "test.pdf")#fontsize設(shè)定字體大小,filename設(shè)定文件名

Generate annotations for rows and columns#為行和列生成注釋

annotation_col = data.frame(
  CellType = factor(rep(c("CT1", "CT2"), 5)), 
  Time = 1:5
)
rownames(annotation_col) = paste("Test", 1:10, sep = "")

annotation_row = data.frame(
  GeneClass = factor(rep(c("Path1", "Path2", "Path3"), c(10, 4, 6)))
)
rownames(annotation_row) = paste("Gene", 1:20, sep = "")

Display row and color annotations#顯示行和列注釋

pheatmap(test, annotation_col = annotation_col)#顯示列注釋
pheatmap(test, annotation_col = annotation_col, annotation_legend = FALSE)#顯示列注釋,并去掉其解說(shuō)
pheatmap(test, annotation_col = annotation_col, annotation_row = annotation_row)#顯示行注釋及列注釋

Change angle of text in the columns更改列中文本的角度

pheatmap(test, annotation_col = annotation_col, annotation_row = annotation_row, angle_col = "45")#下標(biāo)文本傾斜45角書(shū)寫(xiě)
pheatmap(test, annotation_col = annotation_col, angle_col = "0")#下標(biāo)文本水平書(shū)寫(xiě)

Specify colors指定顏色

ann_colors = list(
  Time = c("white", "firebrick"),
  CellType = c(CT1 = "#1B9E77", CT2 = "#D95F02"),
  GeneClass = c(Path1 = "#7570B3", Path2 = "#E7298A", Path3 = "#66A61E")
)#分別設(shè)定3種注釋不同的顏色

pheatmap(test, annotation_col = annotation_col, annotation_colors = ann_colors, main = "Title")
pheatmap(test, annotation_col = annotation_col, annotation_row = annotation_row, 
         annotation_colors = ann_colors)
pheatmap(test, annotation_col = annotation_col, annotation_colors = ann_colors[2]) #把顏色顯示在圖表中

Gaps in heatmaps

pheatmap(test, annotation_col = annotation_col, cluster_rows = FALSE, gaps_row = c(10, 14))#在第10行和14行后分開(kāi)
pheatmap(test, annotation_col = annotation_col, cluster_rows = FALSE, gaps_row = c(10, 14), 
         cutree_col = 2)#縱分為兩部分

Show custom strings as row/col names將自定義字符串顯示為行/列名稱

labels_row = c("", "", "", "", "", "", "", "", "", "", "", "", "", "", "", 
               "", "", "Il10", "Il15", "Il1b")#定義你想要的行名稱

pheatmap(test, annotation_col = annotation_col, labels_row = labels_row)#替換原來(lái)的行名稱

Specifying clustering from distance matrix

drows = dist(test, method = "minkowski")
dcols = dist(t(test), method = "minkowski")
pheatmap(test, clustering_distance_rows = drows, clustering_distance_cols = dcols)
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末扮授,一起剝皮案震驚了整個(gè)濱河市嚎尤,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌卖毁,老刑警劉巖翔脱,帶你破解...
    沈念sama閱讀 217,734評(píng)論 6 505
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件隶糕,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡锉矢,警方通過(guò)查閱死者的電腦和手機(jī)绵估,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,931評(píng)論 3 394
  • 文/潘曉璐 我一進(jìn)店門(mén),熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人,你說(shuō)我怎么就攤上這事辑畦÷嵫裕” “怎么了务漩?”我有些...
    開(kāi)封第一講書(shū)人閱讀 164,133評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵饼煞,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我,道長(zhǎng),這世上最難降的妖魔是什么宏娄? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,532評(píng)論 1 293
  • 正文 為了忘掉前任扛伍,我火速辦了婚禮攘滩,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己伺通,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,585評(píng)論 6 392
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著绢彤,像睡著了一般讥耗。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書(shū)人閱讀 51,462評(píng)論 1 302
  • 那天眉踱,我揣著相機(jī)與錄音大猛,去河邊找鬼。 笑死,一個(gè)胖子當(dāng)著我的面吹牛割卖,可吹牛的內(nèi)容都是我干的鹏溯。 我是一名探鬼主播取试,決...
    沈念sama閱讀 40,262評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼瞬浓,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了弊琴?” 一聲冷哼從身側(cè)響起腋寨,我...
    開(kāi)封第一講書(shū)人閱讀 39,153評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤踱蠢,失蹤者是張志新(化名)和其女友劉穎撕攒,沒(méi)想到半個(gè)月后陡鹃,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,587評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡抖坪,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,792評(píng)論 3 336
  • 正文 我和宋清朗相戀三年萍鲸,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片擦俐。...
    茶點(diǎn)故事閱讀 39,919評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡脊阴,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情嘿期,我是刑警寧澤品擎,帶...
    沈念sama閱讀 35,635評(píng)論 5 345
  • 正文 年R本政府宣布,位于F島的核電站备徐,受9級(jí)特大地震影響萄传,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜蜜猾,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,237評(píng)論 3 329
  • 文/蒙蒙 一盲再、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧瓣铣,春花似錦、人聲如沸贷揽。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,855評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)禽绪。三九已至蓖救,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間印屁,已是汗流浹背循捺。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 32,983評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留雄人,地道東北人从橘。 一個(gè)月前我還...
    沈念sama閱讀 48,048評(píng)論 3 370
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像础钠,于是被迫代替她去往敵國(guó)和親恰力。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,864評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容