前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >我是如何还原NC中的美图的

我是如何还原NC中的美图的

作者头像
作图丫
发布2022-03-29 09:40:34
1.2K0
发布2022-03-29 09:40:34
举报
文章被收录于专栏:作图丫作图丫

导语

GUIDE ╲

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

Fig2b,分为三部分:

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

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

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

R包安装

代码语言:javascript
复制
##bioconductor和github都能安装
if (!requireNamespace("BiocManager", quietly = TRUE))
    install.packages("BiocManager")
BiocManager::install("ComplexHeatmap")
library(ComplexHeatmap)
??ComplexHeatmap

还原绘图

01

编个数据用用吧

mat是基因表达矩阵,tab是特征标签数据框,sampletab是样本标签数据框。

代码语言:javascript
复制
Heatmap(mat)##最基础的热图

02

主体部分聚类热图Heatmap()

代码语言:javascript
复制
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()

代码语言:javascript
复制
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()

代码语言:javascript
复制
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图中颜色标记的基因注释在下方,我的数据中基因为行,所以就加到右边了,但代码是一样的。

代码语言:javascript
复制
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

(略有差别)完整复制的图片来了

代码语言:javascript
复制
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-06-18,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作图丫 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档