Search code examples
rhierarchical-clusteringpheatmapheatmaply

Clustering in pheatmap and heatmaply R packages


I am using the R heatmaply package to produce interactive heatmaps. I like the software, but I would like to get from it the same clustering (ordering of rows and columns) I get using the pheatmap package. Therefore, I would like the two commands to produce the same ouput:

heatmaply (scale (mtcars))
pheatmap  (scale (mtcars))

Is there a way to do this? Thanks in advance. Arturo

P.S. I recently asked another similar question about the color output, i.e., not clustering, output, that was brilliantly answered here: R heatmaply and pheatmap output


Solution

  • Here is a solution to order columns and rows of heatmaply as in pheatmap:

    phtmap <- pheatmap(scale(mtcars))
    heatmaply(scale(mtcars), Rowv=phtmap[[1]], Colv=phtmap[[2]], revC=TRUE)
    

    The ouput of pheatmap enter image description here

    and the output of heatmaply enter image description here