Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matching corrplot and pheatmap in Section 8.3.6.3 #29

Open
vinhtantran opened this issue Apr 29, 2020 · 0 comments
Open

Matching corrplot and pheatmap in Section 8.3.6.3 #29

vinhtantran opened this issue Apr 29, 2020 · 0 comments

Comments

@vinhtantran
Copy link

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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant