【问题标题】:how to add row labels (annotations) in Heatmap如何在热图中添加行标签(注释)
【发布时间】:2017-09-19 22:02:00
【问题描述】:

我有以下脚本用于在 Rstudio 中使用 Heatmap 创建热图。一切看起来都不错,颜色、树状图大小和位置、字体大小、列注释(标签),但我似乎无法添加行标签。

我的数据文件是制表符分隔的文本文件,有一个标题行(热图中的列名),第一列有示例名称(我希望这些在热图中显示为行标签)

这是我的脚本:

source("https://bioconductor.org/biocLite.R")
biocLite("ComplexHeatmap")
library(ComplexHeatmap)
filename <- "Data.txt"

my_data <- read.table(filename, sep ="\t", quote = "", stringsAsFactors =`FALSE,header = TRUE)`

# Make the heatmap data into a matrix
# [all rows, columns 2-13]
# Leave out 1st column (sample names) since they don't not belong in the heatmap

my_matrix <- as.matrix(my_data[ ,c(2:13)]) 

# Cluster by rows only, not columns
# Increase dendogram width
# Change font size to 0.8

Heatmap(my_matrix, cluster_columns = FALSE, 
        column_names_gp = gpar(cex=0.8),
        row_hclust_width = unit(3, "cm"))

一切看起来都很棒,但我的热图上没有行标签(只有列标签)。

【问题讨论】:

    标签: r heatmap


    【解决方案1】:

    抱歉,这有点晚了,但您可以切换矩阵上的行名吗:

    rownames(my_matrix) &lt;- my_matrix[,1]

    然后引入 show_row_names 参数:

    Heatmap(my_matrix, cluster_columns = FALSE, 
                    column_names_gp = gpar(cex=0.8),
                    row_hclust_width = unit(3, "cm")
                    show_row_names = TRUE)
    

    或者您也可以添加行标签作为注释:

    ht  <- Heatmap(my_matrix, cluster_columns = FALSE, 
                    column_names_gp = gpar(cex=0.8),  
                    row_hclust_width = unit(3, "cm"))
    
    ha_row <- rowAnnotation(names = row_anno_text(x = paste( my_matrix[,1]), just = "left", gp = gpar(fontsize = 11) ), show_annotation_name = FALSE)
    
    draw(ht + ha_row)
    

    【讨论】:

      猜你喜欢
      • 2012-09-17
      • 2020-11-05
      • 2019-09-30
      • 2016-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多