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

  • 如果是画简单的热图可以用pheatmap,上手简单,网上教程特别多,画出来很好看(pheatmap缺点:legend位置不可改;colnames和rownames位置不可改,字体大小可改;可在最上面的位置加注释,左右下不可加注释,注释形式只能是颜色,文本和图形都不可以加;可以按行列加gap,便于看分组信息;可以在cell里显示数值大小,数值可以控制小数点位数)
  • 为什么要用complexheatmap?我们看看他强大的功能:


    图片.png

如果你的图需要:

  • 行注释,列注释都有或者其一; 在heatmap四周注释各种图或者文本
  • 画了好几个热图要拼起来(我试过cow_plot,ggarrange总是失败,如果大家成功了可以教我)
  • 图例和注释的图例位置或者方向调整
    -画分类型变量
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

你可能感兴趣的:(complexheatmap,一个强大的画热图的包)