2

I have the following script for creating a heatmap using Heatmap in Rstudio. Everything looks good, the coloring, dendogram size and location, font size, column annotations (labels), but I can't seem to add row labels.

My data file is tab separated text file, with a header row (column names in Heatmap), and the 1st column has the sample names (I want those to show as row labels in Heatmap)

Here is my script:

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"))

Everything looks great, but there are no row labels on my heatmap (only column labels).

1 Answer 1

1

Sorry this is a little late but can you switch the row names on your matrix:

rownames(my_matrix) <- my_matrix[,1]

Then introduce the show_row_names argument:

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

Or alternatively you can add row labels as an annotation:

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.