Search code examples
rcluster-analysisdendrogram

Heatmap dendrogram based on correlation in R


I have a heatmap that looks like this in R:

col<- colorRampPalette(c("red","white", "blue"))(10)
library("gplots")
heatmap.2(qq,scale="none",col=col,trace="none",density.info="none",dendrogram="column")

enter image description here

But then I did a separate cluster analysis based on correlation, that came out like this:

library(Hmisc)
plot(varclus(qq,similarity="spearman"))

enter image description here

How can I modify my heatmap so that the clustering is identical to the cluster analysis I did with correlation? I need to somehow modify the heatmap.2 function (or maybe use a different function) to be based on pearson correlation. Any ideas?


Solution

  • Try

    col<- colorRampPalette(c("red","white", "blue"))(10)
    library("gplots")
    
    library(Hmisc)
    v <- varclus(qq,similarity="spearman")
    
    devtools::install_github('talgalili/dendextend')
    library(dendextend)
    
    dend <- as.dendrogram(v) # comes from dendextend. The same as as.dendrogram(v$hclust)
    
    heatmap.2(qq,scale="none",col=col,trace="none",density.info="none",dendrogram="column", Colv = dend)
    

    (since qq does not exist, I can't reproduce the image)