首页 文章

如何在Heatmap中添加行标签(注释)

提问于
浏览
1

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

我的数据文件是制表符分隔的文本文件,带有 Headers 行(Heatmap中的列名), and the 1st column has the sample names (I want those to show as row labels in 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"))

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

1 回答

  • 0

    对不起,这有点晚了但是你可以在矩阵上切换行名:

    rownames(my_matrix) <- 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)
    

相关问题