1

So I'm trying to create a Heatmap using ComplexHeatmap package and my data has first column as a species name, e.g. "Shigella" and the next 8 columns titled by their sample id represent how many times each species were observed(as a numeric value) in a sample.

To create a Heatmap I need a numeric matrix, so I get it like this my_matrix <- as.matrix(my_data[,c(2:9)]), getting all columns except the first one that contains character values, then I store species name as separate data frame by species_name <- as.data.frame(my_data$species_name) and then what I'm trying to do is assign species name back to their corresponding rows to display in a heatmap by using rownames function, but apparently this doesn't work. Simple example looks something like this:

Heatmap(my_matrix, rownames(species_name), show_row_names = TRUE) 

I get no warnings nor errors, heatmap appears in a plot sections but still doesn't have row names assigned like in the image bellow, and finally my question is how do I assign them proper?

I want my Species name to be displayed as row name, e.g. "Shigella" instead of "row 1", "Salmonella" instead of "row 2", etc.

aynber
  • 22,380
  • 8
  • 50
  • 63
Michael
  • 11
  • 2

1 Answers1

2

You can try -

my_matrix <- as.matrix(my_data[,c(2:9)])
rownames(my_matrix) <- my_data$species_name
Heatmap(my_matrix, show_row_names = TRUE)
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213