Its possible to remove annotation names using anno_simple in ComplexHeatmap
2
0
Entering edit mode
nromerov • 0
@3ef12fd6
Last seen 6 days ago
Colombia

Hello

Im trying to plot a heat map with the code bellow


row_anno <- rowAnnotation(
  CellType = anno_simple(cell_classification$cell_type, col = cluster2celltype_colors),
  CellSubtype = anno_simple(cell_classification$cell_subtype, col = cluster2cellsubtype_colors)
)

col_anno <- columnAnnotation(
  Relationship = anno_simple(module_classification$module_relationship, col = module2relationship_colors),
  Module = anno_simple(module_classification$modules_names, col = module2colors_colors)
)

cell_type_legend <- Legend(
  labels = names(celltype2colors),  # Cell type names
  legend_gp = gpar(fill = celltype2colors),  # Corresponding colors
  title = "Cell Type"
)

cell_subtype_legend <- Legend(
  labels = names(cellsubtype2colors),  # Cell subtype names
  legend_gp = gpar(fill = cellsubtype2colors),  # Corresponding colors
  title = "Cell Subtype"
)

module_relationship_legend <- Legend(
  labels = names(relationship2colors),  # Relationship names
  legend_gp = gpar(fill = relationship2colors),  # Corresponding colors
  title = "Module Relationship"
)

scale_legend <- Legend(
  col_fun = colorRamp2(c(0, 30), c("white", "#B57EDC")),
  title = "Shared Genes",
   at = c(0, 10, 20, 30),
  labels = c("0", "10", "20", "30")
)

vertical_legends <- packLegend(
  module_relationship_legend,
  cell_type_legend,
  direction = "vertical",  
  row_gap = unit(5, "mm")  
)

atlnet_legends <- packLegend(
  cell_subtype_legend,
  vertical_legends,
  direction = "horizontal", 
  column_gap = unit(5, "mm")  
)

combined_legends <- packLegend(
  scale_legend,
  atlnet_legends,
  direction = "vertical",  
  row_gap = unit(5, "mm")  
)

lhm <- Heatmap(modules_leiden_matrix, name = "Shared Genes", 
        col = colorRamp2(c(0, max(modules_leiden_matrix)), c("white", "#B57EDC")),
        cluster_rows = FALSE, cluster_columns = FALSE,
        left_annotation = row_anno,  
        top_annotation = col_anno,    
        show_row_names = FALSE,       
        show_column_names = FALSE,
        show_heatmap_legend = FALSE
)

draw(lhm, annotation_legend_list = combined_legends)

and i got this enter image description here

Someone know how can i remove the labels from the annotations of the heatmap?

ComplexHeatmap • 232 views
ADD COMMENT
0
Entering edit mode
@james-w-macdonald-5106
Last seen 7 hours ago
United States

It's possible (most anything is possible with R, being as it and all packages are OpenSource), but not easy to do. You would have to modify the SimpleAnnotation objects you generate directly, as the API doesn't supply a way to do it. And the reason the API doesn't provide a way to remove those labels is that it doesn't make sense to do so. If you strip off the names, then you have removed any ability to interpret.

> mat <- matrix(rnorm(100), 10)
> ha <- HeatmapAnnotation("noname" = rnorm(10), which = "column")
## as a general rule, if you find yourself using the @ function, it is a bad idea...
> ha@anno_list[[1]]@name_param$show = FALSE
> Heatmap(mat, top_annotation = ha)

enter image description here

0
Entering edit mode

But then maybe I misinterpret what you mean by 'remove the labels from the annotations' which could mean several different things....

0
Entering edit mode
@df6c68e9
Last seen 4 hours ago
United States

Setting show_annotation_name=FALSE in HeatmapAnnotation() also works, assuming this is what you were asking for. However, I also agree that this is a bad idea.

On a different note, it seems like each column is being assigned a different module color. Why not just use the modules as column labels? Same idea for cell subtype: just set those as the row labels. The cell type row annotation could also be removed if rows were instead split by type.

ADD COMMENT

Login before adding your answer.

Traffic: 498 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