I have a tab delimited text file with a header (sample metrics), and 1st column contains sample names, hypothetically something like this:
My actual table has 13 columns.
SAMPLE NAME | EUROPEAN | ASIAN | AFRICAN |
---|---|---|---|
Grejoujkd | 24 | 5 | 1 |
Ljkiuiuiuo | 5 | 46 | 3 |
Mkjkueeyy | 25 | 3 | 20 |
I would like the sample names to be row labels on the heatmap, and Metrics (European, Asian, African) to be column labels.
Using this simple script, the column labels got printed, but the row labels did not. Any suggestions on how to add the row labels (sample names) to the heatmap:
library(ComplexHeatmap)
filename <- "Data.txt"
# Read the data into a data frame
my_data <- read.table(filename, sep ="\t", quote = "", stringsAsFactors = FALSE,header = TRUE)
# Make the heatmap data into a matrix
my_matrix <- as.matrix(my_data[ ,c(2:13)]) # [all rows, columns 2-13]
# Make heatmap
Heatmap(my_matrix)
Here is my heatmap which shows that the row labels did not print
https://drive.google.com/file/d/0B-ObXiVfL-RzZWZfWW95S25oVjA/view?usp=sharing
Thanks for the feedback. I added row.names, but for some reason the program Complexheatmap does not function properly when row.names are added. Works fine with heatmap.2 though.
Here is what I added. Everything else the same as above:
my_data <- read.table(filename, sep ="\t", quote = "",
stringsAsFactors = FALSE,header = TRUE, row.names=1)
Here is the error message I got:
> my_matrix <- as.matrix(my_data[ ,c(2:13)]) # [all rows, columns 2-13]
Error in `[.data.frame`(my_data, , c(2:13)) : undefined columns selected
When I changed this to :
my_matrix <- as.matrix(my_data)
the error message went away, but now the heatmap is messed up.
I checked all the documentation and examples for Complexheatmap, and it seems there is no example or heatmap shown with BOTH row and column labels, so I am not sure if Complexheatmap has that functionality and can out output BOTH row and column labels simultaneously.
Everything plots great with heatmap.2, but I like complexheatmap because it is more versatile. However, complexheatmap seems to have a MAJOR HANDICAP in that you can't output BOTH row and column labels simultaneously.
Any feedback will be greatly appreciated.
I am not sure you checked all the documentation and examples for ComplexHeatmap because literally the very first example has both row and column names! From ?Heatmap:
In addition:
Thanks alot for the reply. The only problem with this is my data frame has 100 rows and 13 columns, so it would take forever to manually enter each vector value. Is there a way to feed the whole data frame without specifying each of the 1300 values in the matrix individually?