How to create correlation matrix plot in R?

To create a correlation matrix plot, we can use ggpairs function of GGally package. For example, if we have a data frame called df that contains five columns then the correlation matrix plot can be created as ggpairs(df). A correlation matrix plot using ggpairs display correlation value as well as scatterplot and the distribution of variable on diagonal.

Example

library(GGally)
ggpairs(df)

Output

Updated on: 2026-03-11T23:22:53+05:30

458 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements