ComplexHeatmap专画复杂的热图的R包

上个月我们分享了基于多组学数据识别关键癌症驱动基因的超实用工具Moonlight,不知道大家是否有注意到传说中“别人家的图”。

Fig2b,分为三部分:

上图为细胞系表达水平的箱线图。中间为热图,显示乳腺癌及其相关生物学过程中预测的抑癌基因和癌基因top50。基于欧氏距离矩阵进行层次聚类。下图是颜色标记不同注释信息。红色(蓝色)标记Moonlight基因得分加(减)的生物过程。特定基因突变的样本数量从白色到深紫色不等。超甲基化DMR显示为蓝色,去甲基化黄色。KM生存预后差的基因标记为粉红色。启动子区域的染色质开放性展示为白色(关闭)—橙色。

猛一看有点复杂┗|`O′|┛ 嗷~~莫不是要单独画出三部分图再拼接到一起?也不是不行,本小编以前画图就只会用笨方法。。。

后来,我找到了这个神器——ComplexHeatmap。看这个R包的直译就知道啦,它是用来画复杂的热图。那到底有多复杂?小编带你一览庐山真面目。

R包安装
##bioconductor和github都能安装if (!requireNamespace("BiocManager", quietly = TRUE))    install.packages("BiocManager")BiocManager::install("ComplexHeatmap")library(ComplexHeatmap)??ComplexHeatmap
还原绘图
01
编个数据用用吧
mat是基因表达矩阵,tab是特征标签数据框,sampletab是样本标签数据框。

Heatmap(mat)##最基础的热图

02
主体部分聚类热图Heatmap()
Heatmap(mat,row_split = tab[,2],##分类标签width = unit(18, "cm"), height = unit(18, "cm"),##热图主体的大小show_heatmap_legend = FALSE,##是否展示图例cluster_row_slices = FALSE,##去掉虚线row_title_rot = 0,##行标签竖向显示cell_fun = function(j, i, x, y, width, height, fill) {grid.text(sprintf("%.1f", mat[i, j]), x, y, gp = gpar(fontsize = 10))},##热图添加数值)##加图例col_fun = colorRamp2(c(-2,0,2), c("blue", "white", "red"))lgd = Legend(col_fun = col_fun, title = "expr_value")draw(lgd,x = unit(24, "cm"), y = unit(25, "cm"),just = c("right", "top"))##数值要做调整

03
加上部的箱线图anno_boxplot()
Heatmap(mat,row_split = tab[,2],##分类标签width = unit(18, "cm"), height = unit(18, "cm"),##show_heatmap_legend = FALSE,##是否展示图例cluster_row_slices = FALSE,##去掉虚线row_title_rot = 0,##行标签竖向显示cell_fun = function(j, i, x, y, width, height, fill) {grid.text(sprintf("%.1f", mat[i, j]), x, y, gp = gpar(fontsize = 10))},##热图添加数值
top_annotation = HeatmapAnnotation(foo = anno_boxplot(mat, height = unit(4, "cm"),  gp = gpar(fill = 1:24),##填充颜色  box_width = 0.3,##箱子宽度  outline = FALSE##是否显示离群点  ))##将列注释放到热图中)
col_fun = colorRamp2(c(-2,0,2), c("blue", "white", "red"))lgd = Legend(col_fun = col_fun, title = "expr_value")draw(lgd,x = unit(26, "cm"), y = unit(23, "cm"),just = c("right", "top"))##数值要做调整

还可以添加不同形式的列注释:

加到左侧left_annotation = rowAnnotation()的块注释anno_block()

加到右侧right_annotation = rowAnnotation()的直方图注释anno_histogram()

Heatmap(mat,row_split = tab[,2],##分类标签width = unit(18, "cm"), height = unit(18, "cm"),##show_heatmap_legend = FALSE,##是否展示图例cluster_row_slices = FALSE,##去掉虚线row_title_rot = 0,##行标签竖向显示cell_fun = function(j, i, x, y, width, height, fill) {grid.text(sprintf("%.1f", mat[i, j]), x, y, gp = gpar(fontsize = 10))},##热图添加数值top_annotation = HeatmapAnnotation(foo = anno_boxplot(mat, height = unit(4, "cm"),gp = gpar(fill = 1:24),##填充颜色box_width = 0.3,##箱子宽度outline = FALSE##是否显示离群点)),##将列注释放到热图中
left_annotation = rowAnnotation(foo = anno_block(gp = gpar(fill = 2:3))),right_annotation = rowAnnotation(foo = anno_histogram(mat,gp = gpar(fill = 2:3))),)

右侧密度图注释anno_density()

04
加下方颜色注释
Fig2b图中颜色标记的基因注释在下方,我的数据中基因为行,所以就加到右边了,但代码是一样的。
Heatmap(mat,row_split = tab[,2],##分类标签width = unit(18, "cm"), height = unit(18, "cm"),##show_heatmap_legend = FALSE,##是否展示图例cluster_row_slices = FALSE,##去掉虚线row_title_rot = 0,##行标签竖向显示cell_fun = function(j, i, x, y, width, height, fill) {grid.text(sprintf("%.1f", mat[i, j]), x, y, gp = gpar(fontsize = 10))},##热图添加数值top_annotation = HeatmapAnnotation(foo = anno_boxplot(mat, height = unit(4, "cm"),  gp = gpar(fill = 1:24),##填充颜色  box_width = 0.3,##箱子宽度  outline = FALSE##是否显示离群点  )),##将列注释放到热图中  ##根据特征标签数据框tab来标注  right_annotation = rowAnnotation(target = tab$target,   expr = tab$expr,mutation=tab$mutation))

05
(略有差别)完整复制的图片来了
Heatmap(mat,row_split = tab[,2],##分类标签width = unit(16, "cm"), height = unit(16, "cm"),##show_heatmap_legend = FALSE,##是否展示图例cluster_row_slices = FALSE,##去掉虚线row_title_rot = 0,##行标签竖向显示cell_fun = function(j, i, x, y, width, height, fill) {grid.text(sprintf("%.1f", mat[i, j]), x, y, gp = gpar(fontsize = 10))},##热图添加数值top_annotation = HeatmapAnnotation(foo = anno_boxplot(mat, height = unit(4, "cm"),  gp = gpar(fill = 1:24),##填充颜色  box_width = 0.3,##箱子宽度  outline = FALSE##是否显示离群点  )),##将列注释放到热图中#right_annotation = rowAnnotation(target = tab$target, expr = tab$expr,mutation=tab$mutation),bottom_annotation = HeatmapAnnotation(age = sampletab$age, sex = sampletab$sex,clinical=sampletab$clinical),)
col_fun = colorRamp2(c(-2,0,2), c("blue", "white", "red"))lgd = Legend(col_fun = col_fun, title = "expr_value")draw(lgd,x = unit(27, "cm"), y = unit(25, "cm"),just = c("right", "top"))##数值要做调整

是不是很神似啊。
小编总结
ComplexHeatmap由顾祖光博士创建,是一个全面绘制复杂热图的R包,利用它你能绘制许多文献中的图片并学习到美图的精髓。像小编我这样的手残星人都能复制出来,你还没有信心么???欢迎大家留言探讨~~
统计与绘图

如何选择合适的回归模型

2020-8-28 4:32:38

统计与绘图

ggdark绘出高级感的图形

2020-8-28 4:40:46

声明 本网站部分文章源于互联网,出于传递更多信息和学习之目的转载,并不保证内容正确或赞同其观点。
如转载稿涉及失效、版权等问题,请立即联系管理员;我们会予以修改、删除相关文章,请留言反馈
Notice: When your legal rights are being violated, please send an email to: [email protected].
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索