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!