Skip to content

Matching corrplot and pheatmap in Section 8.3.6.3 #29

@vinhtantran

Description

@vinhtantran

I accidentally ran by your bookdown when I searched for how to display correlation matrix with hierarchical clustering tree. I noticed that your corrplot(correlationMatrix, order = 'hclust', addrect = 2) plot doesn't match with your pheatmap below in terms of variables' order and clustering. It's because in corrplot, the function takes the correlation matrix as a distance matrix and runs hclust directly on it. Meanwhile, pheatmap considers the correlation matrix as a normal data set and re-calculates the distance matrix before feeding it into hclust.

To make the two plots consistent with each other, I suggest changing pheatmap function to add two arguments (clustering_distance_rows and clustering_distance_cols) to it. It basically tells pheatmap to use the current correlation matrix as the distance matrix. The 1 - is to ensure that perfect positive correlation (1) is considered as min distance and perfect negative correlation (-1) is considered as max distance.

pheatmap(correlationMatrix, 
         clustering_distance_rows = as.dist(1 - correlationMatrix), 
         clustering_distance_cols = as.dist(1 - correlationMatrix))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions