Is it possible to add a dendrogram as a top annotation using ComplexHeatmap ?
2
0
Entering edit mode
18 months ago
Manuel ▴ 10

I want to had a custom dendrogram to an heatmap. I know I can add like this:

dend = as.dendrogram(hclust(dist(gene_matrix), method = 'ward.D'))
dend = color_branches(dend, k = 4)
Heatmap(gene_matrix, name = "Altered",top_annotation= colAnn, cluster_columns = dend,
        column_dend_reorder = FALSE)

However, even when I had column_dend_reorder, it automatically reorders the columns that are already ordered in the dendrogram.

When I remove the cluster_columns=dend it does not reorder the columns and create a dendrogram, yet the dendrogram created is not with the same method that I want and it not colored.

So want to remove the dendrogram from the heatmap, and add 'dend' as a top annotation.

How can I do that?

Thanks!

Dendrogram R Heatmap ComplexHeatmap • 949 views
ADD COMMENT
1
Entering edit mode
18 months ago
Ram 44k

I don't think that's possible. A dendrogram is not a per-column annotation, it's a representation of a hierarchically clustered distance matrix generated using all columns. You can access the dendrogram using Heatmap Decoration functions after drawing the heatmap, but you can't add a dendrogram as an annotation.

I think this is an XY problem - why do you need to access the dendrogram as an annotation? Do you need to reorder other column annotations / move the dendrogram?

ADD COMMENT
1
Entering edit mode
18 months ago
jv ★ 1.8k

this chapter of the ComplexHeatmap reference makes it look like you can add a custom dendrogram so long as you have an hclust object. The key looks to be using cluster_columns = as.dendrogram(hclust_obj)

ADD COMMENT

Login before adding your answer.

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