Skip to content

row annotations misalign when row_km is used with anno_mark() #1245

@Eomesodermin

Description

@Eomesodermin

Bug Report: anno_mark() row annotations misalign when row_km is used

Description

When using ComplexHeatmap::anno_mark() to annotate specific rows, the labels are positioned correctly under default conditions. However, when applying row_km (row k-means clustering), the row order is altered after the annotation is constructed, causing labels to be misaligned or disappear.

There appears to be no supported way to delay or recompute at = positions after clustering, making gene labeling incompatible with row_km.


Minimal reproducible example

library(ComplexHeatmap)
library(circlize)
set.seed(42)

# Simulate data: 50 genes x 10 samples
mat <- matrix(rnorm(500), nrow = 50, ncol = 10)
rownames(mat) <- paste0("Gene", 1:50)
colnames(mat) <- paste0("Sample", 1:10)

# Define genes to annotate
genes.to.label <- c("Gene2", "Gene10", "Gene25", "Gene40", "Gene45")
label.positions <- match(genes.to.label, rownames(mat))

# Create annotation
row.anno <- rowAnnotation(
mark = anno_mark(
  at = label.positions,
  labels = genes.to.label
)
)

# Test 1 - no clustering (correct labels)
Heatmap(
mat,
name = "Expression",
right_annotation = row.anno,
cluster_rows = FALSE
)

Image

# Test 2 - with clustering (correct labels)
Heatmap(
mat,
name = "Expression",
right_annotation = row.anno,
cluster_rows = TRUE
)

Image

# Test 3 - k means (breaks labels)
Heatmap(
mat,
name = "Expression",
right_annotation = row.anno,
row_km = 2
)

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions