jokergoo / ComplexHeatmap

Make Complex Heatmaps
https://jokergoo.github.io/ComplexHeatmap-reference/book/
Other
1.3k stars 230 forks source link

Hide Heatmap but keep annotations and dendograms? #716

Closed ahdee closed 3 years ago

ahdee commented 3 years ago

Hi weird question, but I really like how easy it is to add annotations with dendograms. Is there a way to just plot everything the same but somehow hide/ignore the heatmap portion. Here is an example:

nof_elem <- 4

set.seed(123)
mat <- matrix(rnorm(nof_elem * nof_elem), nof_elem)
rownames(mat) <- paste0("R", 1:nof_elem)
colnames(mat) <- paste0("C", 1:nof_elem)
mat

column_ha <- HeatmapAnnotation(cluster = anno_block(
  gp = gpar(fill = 2:15),
  labels = c("group1", "group2", "group3"),
  labels_gp = gpar(col = "white", fontsize = 10),

  # Tried this but didn't work
  # col = list(cluster = c("group1" = "red", "group2" = "blue", "group3" = "black"))
))

Heatmap(mat,
        cluster_columns = TRUE,
        cluster_rows = FALSE,
        top_annotation = column_ha,
        column_split = c(1, 2, 2, 3),
        show_column_names = FALSE
)
jokergoo commented 3 years ago

Yes, you can :)

First, calculate the column dendrogram with mat; second, use a zero-row matrix for Heatmap():

column_dend = hclust(dist(t(mat)))

Heatmap(matrix(nrow = 0, ncol = ncol(mat)),
        cluster_columns = column_dend,
        top_annotation = column_ha,
        column_split = 3
)

image

ahdee commented 3 years ago

That is awesome, thanks a bunch. Looks great.