myflow
myflow

Reputation: 95

Inconsistent clustering with ComplexHeatmap?

So I'm trying to generate a heatmap for my data using Bioconductor's ComplexHeatmap package, but I get slightly different results depending on whether I make the dendrogram myself, or tell Heatmap to make it.

Packages:

require(ComplexHeatmap)
require(dendextend)

Data:

a=rnorm(400,1)
b=as.matrix(a)
dim(b)=c(80,5)

If I make the dendrogram myself:

d=dist(b,method="euclidean")
d=as.dist(d)
h=hclust(d,method="ward.D")
dend=as.dendrogram(h)

Heatmap(b,
    cluster_columns=FALSE,
    cluster_rows = dend)

Versus having Heatmap do the clustering:

Heatmap(b,
    cluster_columns=FALSE,
    clustering_distance_rows = "euclidean",
    clustering_method_rows = "ward.D") 

They tend to look very similar, but they'll be very slightly different.

And this matters a lot for my data. Heatmap's clustering ends up organizing my data way, way better, however, I also want to extract the list of clustered items via like cutree(), but I don't think I can extract it from Heatmap's clustering.

Does anyone know what's going on?

Upvotes: 1

Views: 1169

Answers (1)

Pascal Martin
Pascal Martin

Reputation: 311

the dendrograms are the same. The only thing that changes is the ordering. You can verify this using:

hmap1 <- Heatmap(b,
                 cluster_columns=FALSE,
                 cluster_rows = dend)

hmap2 <- Heatmap(b,
                 cluster_columns=FALSE,
                 clustering_distance_rows = "euclidean",
                 clustering_method_rows = "ward.D") 

#Reorder both row dendrograms using the same weights:
rowdend1 <- reorder(row_dend(hmap1)[[1]], 1:80)
rowdend2 <- reorder(row_dend(hmap2)[[1]], 1:80)

#check that they are identical:
identical( rowdend1, rowdend2)
## [1] TRUE

The ComplexHeatmap::Heatmap function has an argument row_dend_reorder with default value TRUE that you should check.

Upvotes: 2

Related Questions