如何在Heatmap

时间:2017-09-19 22:02:01

标签: r heatmap

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

我的数据文件是制表符分隔的文本文件,带有标题行(热图中的列名称),,第1列包含样本名称(我希望那些在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 :(得分: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)