ComplexHeatmap removes row labels if annotation is added
1
0
Entering edit mode
alexw858 • 0
@alexw858-21465
Last seen 4.3 years ago

Hi all,

I am experiencing an issue with my heatmap. When I draw a heatmap with row annotations, my row names disappear. I can restore the row names by removing the annotations, but nothing else seems to cause the issue. Here is the heatmap call and draw function:

  Wx1 <- Heatmap(Cx[[i]][[1]],
      show_row_names=F, column_names_gp=gpar(fontsize=8),
      clustering_distance_rows = distr,clustering_method_rows = method, 
      name="Log10Dunn",row_title=paste("C",i," - Percent and Dunn-Pvals"),col=cf2, 
      cluster_rows = cluster_within_group(t(Cx[[i]] 
      [[2]]), group), row_split = 6, border = TRUE)

  cids <- column_order(Wx1);

  Wx2 <- Heatmap(Cx[[i]][[2]][,cids],
      show_row_names=T, row_names_gp=gpar(fontsize=8), column_names_gp=gpar(fontsize=8), 
      cluster_columns=FALSE, clustering_distance_rows = distr,
      clustering_method_rows = method, name="Z-scores",row_title=paste("Heatmap C",i, sep=''),
      col=cf, cluster_rows = cluster_within_group(t(Cx[[i]][[1]]), group), row_split = 6, border = TRUE)

  draw(Wx1+Wx2+row_annotation)
  dev.off();

Cx is the object that contains my matrices, and row_annotation is a Formal class HeatmapAnnotation object. The following code will produce my heatmaps side-by-side and the row annotation on the far right, followed by the legend. There are no labels for rows, yet I know the data exists because draw(Wx1+Wx2) restores the row labels next to the right heatmap. I've tried changing the margins, changing the order of things, setting show_row_names to true or false, and visualizing the output in RStudio's Plots window (instead of the PDF export currently used) to no avail.

Is there anything about annotations that can hide row names by default? If so, how do I force them to show up?

Thanks for taking the time to read!

annotation show_row_names complexheatmap • 7.6k views
ADD COMMENT
3
Entering edit mode
Zuguang Gu ▴ 290
@zuguang-gu-7797
Last seen 28 days ago
Germany / Heidelberg / DKFZ

Hi, that is the default behavior of the new version of the package :) because I feel they don't look nice if the row names are drawn between heatmap and row annotations, and also row names might be duplicated across parallel heatmaps. Only the row names on the most right size of all heatmaps/row annotations will be shown by default. To show the row names which are between your heatmap and row annotation, you can do:

ht = Heatmap(...)
draw(ht, auto_adjust = FALSE)

See https://jokergoo.github.io/ComplexHeatmap-reference/book/a-list-of-heatmaps.html#automatic-adjustment-to-the-main-heatmap for more details.

If you want to add row names on the most right side of your heatmaps, i.e., on the right side of your row annotation, you can add the row names as a text annotation:

ht = Heatmap(...)
ht + rowAnnotation(rn = anno_text(rownames(mat)))
ADD COMMENT
0
Entering edit mode

Thank you! 'ht + rowAnnotation(rn = anno_text(rownames(mat)))' gave me the exact output I was looking for.

ADD REPLY

Login before adding your answer.

Traffic: 847 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6