Search code examples
rpheatmap

Can you have a lower or upper triangular matrix plot when plotting correlations using pheatmap in R?


Say we use the mtcars data from corrplot. How can we obtain a triangular matrix plot using pheatmap?

library(corrplot)
library(pheatmap)

M <- cor(mtcars)
pheatmap(M)


Solution

  • This is a simple way to get a triangular matrix plot from pheatmap.

    M[lower.tri(M)] <- NA
    pheatmap(M, cluster_rows=F, cluster_cols=F, na_col="white")
    

    enter image description here