熱圖(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)