Assign custom dendrogram to ComplexHeatmap Heatmap object
1
0
Entering edit mode
enricoferrero ▴ 570
@enricoferrero-6037
Last seen 8 months ago
Switzerland

Hello,

Is there a way to assign a custom (row) dendrogram and ordering to a Heatmap object generated by ComplexHeatmap Heatmap() function?

After finding out about the row_dend() and row_order() functions, I would have thought something like this would work:

library(ComplexHeatmap)

mat <- matrix(rnorm(1000), ncol=10, nrow=10)
# calculate Spearman correlation
mat.cor <- cor(t(mat), method = "spearman")
# calculate distance based on correlation matrix
mat.dist <- as.dist(1 - abs(mat.cor))
# hierarchical clustering
mat.hc <- hclust(mat.dist, method = "ward.D2")
# dendrogram
mat.dend <- as.dendrogram(mat.hc)

# create heatmap
hm <- Heatmap(mat)

# substitute row dendrogram and order
row_dendro(hm)[[1]] <- mat.dend
row_order(hm)[[1]] <- order.dendrogram(mat.dend)

# plot heatmap with custom row dendrogram and ordering
print(hm)

However, I get these errors:

row_dend(hm)[[1]] <- mat.dend
Error in row_dend(hm)[[1]] <- mat.dend :
could not find function "row_dend<-"
row_order(hm)[[1]] <- order.dendrogram(mat.dend)
Error in row_order(hm)[[1]] <- order.dendrogram(mat.dend) :
could not find function "row_order<-"

The two functions work fine when called on the Heatmap object, it's only the assignment that fails.

Thank you!

ADD COMMENT
2
Entering edit mode
jokergoo ▴ 130
@jokergoo-8506
Last seen 4 weeks ago
Germany

mat.dend can be assigned to cluster_rows argument:

Heatmap(mat, cluster_rows = mat_dend)

which means cluster_rows can be a logical value which controls whether do clustering, it can also be a hclust or a dendrogram object which already contains a customized clustering object.

ADD COMMENT

Login before adding your answer.

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