ComplexHeatmap包绘制热图(二)

前面我介绍了如何利用ComplexHeatmap包绘制简单的热图,现在我们绘制一个稍微复杂一些的热图
首先还是配置数据

data=matrix(rnorm(100),nrow=10)
colnames(data)=paste0('sample',1:10)
rownames(data)=paste0('gene',1:10)
head(data)

在这里插入图片描述准备另外一个数据

anno_row=as.matrix(1:10)
rownames(anno_row)=paste0('gene',1:10)
colnames(anno_row)='bar_data'
anno_row

在这里插入图片描述

p1=Heatmap(data,
           col=c('blue','white','red'),
           cluster_rows = TRUE, 
           cluster_columns = TRUE,
           name='expression',
           column_title = "samples",
           column_title_side="bottom")
p2 = rowAnnotation(width = unit(2, "cm"),
                   bar_data = anno_barplot(anno_row,
                                          border = FALSE, 
                                          axis = TRUE,
                                          gp = gpar(fill = "grey50",
                                                    col = "white"),
                                          bar_with = 0.8,
                                          baseline=0))
p1+p2

在这里插入图片描述这时候绘制的热图加bar图已经出现原形了
但是我也发现行名无法显示,这时候我们可以在p1的左侧加一个标签,或者是P2的右侧加一个文本
左侧加标签

left_anno=data.frame(gene_id=rownames(data))
left_annos = HeatmapAnnotation(df = left_anno,which = "row")
p1=Heatmap(data,
           col=c('blue','white','red'),
           cluster_rows = TRUE, 
           cluster_columns = TRUE,
           name='expression',
           column_title = "samples",
           column_title_side="bottom",
           left_annotation=left_annos)
p2 = rowAnnotation(width = unit(2, "cm"),
                   bar_data = anno_barplot(anno_row,
                                          border = FALSE, 
                                          axis = TRUE,
                                          gp = gpar(fill = "grey50",
                                                    col = "white"),
                                          bar_with = 0.8,
                                          baseline=0))
p1+p2

在这里插入图片描述右侧加文本

p1=Heatmap(data,
           col=c('blue','white','red'),
           cluster_rows = TRUE, 
           cluster_columns = TRUE,
           name='expression',
           column_title = "samples",
           column_title_side="bottom",
           left_annotation=left_annos)
p2 = rowAnnotation(width = unit(2, "cm"),
                   bar_data = anno_barplot(anno_row,
                                          border = FALSE, 
                                          axis = TRUE,
                                          gp = gpar(fill = "grey50",
                                                    col = "white"),
                                          bar_with = 0.8,
                                          baseline=0))
p3=rowAnnotation(text = row_anno_text(rownames(data)), 
                 width = max_text_width(rownames(data)))
p1+p2+p3

在这里插入图片描述当然ComplexHeatmap包绘制的不仅仅如此,还有很多其他的功能,这里先不介绍了,有兴趣的小伙伴可以研究研究哈!

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值