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包繪製的不僅僅如此,還有很多其他的功能,這裏先不介紹了,有興趣的小夥伴可以研究研究哈!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章