Search code examples
rheatmaphierarchical-clusteringdendrogram

Dendrogram and heatmap on similarity matrix


I have already computed a similarity matrix for pairwise comparisons of my data, and I want to use hierarchical clustering and a heatmap to visualize the data.

The heatmap isn't an issue, but for the hierarchical clustering, it seems to be doing a distance matrix of my similarity matrix (I am using package aheatmap if that changes things), and then clustering.

What is the best way to specify that it is already a similarity matrix and cluster based on that data, next to the figure of the heatmap?

Thanks!


Solution

  • You should be able to specify your pairs to aheatmap. I tried it out with the iris package.

    NMF::aheatmap(iris[, 3:4]) # The default uses euclidean
    NMF::aheatmap(iris[, 3:4], Rowv = 'manhattan', Colv = 'euclidean') # Specify what type of distance method to use on rows, and columns.
    

    It also says you can pass external clustering to it. See the ?NMF::aheatmap help file for more.

    hc <- hclust(dist(x, method = 'minkowski'), method = 'centroid')
    aheatmap(x, Rowv = hc, info = TRUE)