complexheatmap,一个强大的画热图的包

2020-05-14  本文已影响0人  TheMoonAsaKite

如果你的图需要:

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拼起来,还可以自己调图之间的间距,图的大小

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

调间距:

draw(ht_list + ht_list, gap = unit(c(3, 6, 9, 0), "mm"))
图片.png

调大小

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.图例方向调整

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
上一篇下一篇

猜你喜欢

热点阅读