- 如果是畫簡單的熱圖可以用pheatmap,上手簡單,網(wǎng)上教程特別多,畫出來很好看(pheatmap缺點:legend位置不可改;colnames和rownames位置不可改,字體大小可改;可在最上面的位置加注釋,左右下不可加注釋,注釋形式只能是顏色,文本和圖形都不可以加;可以按行列加gap,便于看分組信息;可以在cell里顯示數(shù)值大小,數(shù)值可以控制小數(shù)點位數(shù))
-
為什么要用complexheatmap?我們看看他強大的功能:
圖片.png
如果你的圖需要:
- 行注釋,列注釋都有或者其一; 在heatmap四周注釋各種圖或者文本
- 畫了好幾個熱圖要拼起來(我試過cow_plot,ggarrange總是失敗,如果大家成功了可以教我)
- 圖例和注釋的圖例位置或者方向調(diào)整
-畫分類型變量
complexheatmap用起來!
1.行列注釋:
這個柱子可以換成文本或者圖
ha = HeatmapAnnotation(df = df, which = "row", width = unit(1, "cm"))
ht1 = Heatmap(mat, name = "ht1")
ht1 + ha + ht1

圖片.png
ht1 = Heatmap(mat, name = "ht1", km = 2)
ha_boxplot = HeatmapAnnotation(boxplot = anno_boxplot(mat, which = "row"),
which = "row", width = unit(2, "cm"))
draw(ha_boxplot + ht1, row_hclust_side = "left", row_sub_title_side = "right")

圖片.png
ha_column1 = HeatmapAnnotation(points = anno_points(rnorm(10)))
ht1 = Heatmap(mat, name = "ht1", km = 2, row_title = "Heatmap 1", column_title = "Heatmap 1",
top_annotation = ha_column1)
ha_column2 = HeatmapAnnotation(df = data.frame(type = c(rep("a", 5), rep("b", 5))))
ht2 = Heatmap(mat, name = "ht2", row_title = "Heatmap 2", column_title = "Heatmap 2",
bottom_annotation = ha_column2)
ht_list = ht1 + ht2
draw(ht_list, row_title = "Heatmap list", column_title = "Heatmap list",
heatmap_legend_side = "right", annotation_legend_side = "left")

圖片.png
2.把多個heatmap拼起來,還可以自己調(diào)圖之間的間距,圖的大小
ha = HeatmapAnnotation(points = anno_points(rnorm(10)))
ht2 = Heatmap(mat, name = "ht2", column_title = "Heatmap 2", top_annotation = ha, show_heatmap_legend = FALSE)
lgd = legendGrob(c("dots"), pch = 16)
draw(ht1 + ht2, annotation_legend_list = list(lgd))

圖片.png
調(diào)間距:
draw(ht_list + ht_list, gap = unit(c(3, 6, 9, 0), "mm"))

圖片.png
調(diào)大小
ht1 = Heatmap(mat, name = "ht1", column_title = "Heatmap 1")
ht2 = Heatmap(mat, name = "ht2", column_title = "Heatmap 2", width = unit(5, "cm"))
ht1 + ht2

圖片.png
3.圖例方向調(diào)整
df = data.frame(type = c(rep("a", 5), rep("b", 5)))
ha = HeatmapAnnotation(df = df, col = list(type = c("a" = "red", "b" = "blue")))
ht1 = Heatmap(mat, name = "ht1", column_title = "Heatmap 1", top_annotation = ha)
ht2 = Heatmap(mat, name = "ht2", column_title = "Heatmap 2")
ht_list = ht1 + ht2
draw(ht_list)

圖片.png
draw(ht_list, heatmap_legend_side = "left", annotation_legend_side = "bottom")

圖片.png
