
Fig2b,分为三部分:
上图为细胞系表达水平的箱线图。中间为热图,显示乳腺癌及其相关生物学过程中预测的抑癌基因和癌基因top50。基于欧氏距离矩阵进行层次聚类。下图是颜色标记不同注释信息。红色(蓝色)标记Moonlight基因得分加(减)的生物过程。特定基因突变的样本数量从白色到深紫色不等。超甲基化DMR显示为蓝色,去甲基化黄色。KM生存预后差的基因标记为粉红色。启动子区域的染色质开放性展示为白色(关闭)—橙色。
猛一看有点复杂┗|`O′|┛ 嗷~~莫不是要单独画出三部分图再拼接到一起?也不是不行,本小编以前画图就只会用笨方法。。。
后来,我找到了这个神器——ComplexHeatmap。看这个R包的直译就知道啦,它是用来画复杂的热图。那到底有多复杂?小编带你一览庐山真面目。
##bioconductor和github都能安装
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install("ComplexHeatmap")
library(ComplexHeatmap)
??ComplexHeatmap

Heatmap(mat)##最基础的热图
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"))##数值要做调整
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()
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))
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"))##数值要做调整