0
votes

I'm using the "ComplexHeatmap" package to create a heatmap of the correlations in a matrix. I want to use my own clustering for the dendrogram of the heatmap so I run the code below:

library(ComplexHeatmap);
mat = matrix(rnorm(800),80,10);
cor.mat= cor(mat)
dist.mat = (1-cor.mat)/2;
rowdist = dist(as.matrix(dist.mat), method = "euclidean")
rowcluster = hclust(rowdist, method = "ward.D2")
coldist = dist(t(as.matrix(dist.mat)), method = "euclidean")
colcluster = hclust(coldist, method = "ward.D2")
par(mfrow=c(1,2));plot(rowcluster);plot(colcluster);
Heatmap(cor.mat ,cluster_rows=rowcluster, cluster_columns=colcluster)

Problem is, I get different clustering on the rows and columns (asymmetrical), despite the fact that the cluster objects are the same. Even if I pass the Heatmap function the exact same object for rows and columns it still displays a different order for rows and columns. if I just create the dendrograms i.e. plot(rowcluster) or plot(colcluster) they are identical.

I want to get a symmetrical heatmap. Any idea why this happens? Thanks

1

1 Answers

1
votes

Use rowclust=colclust.

No need to transpose.

But note that you have a distance matrix already, so "euclidean" is wrong. You are computing a distance matrix of your distance matrix!