Correlogram with the ellipse package



This post explains how to build a correlogram based on ellipses with the ellipse R package. It provides several reproducible examples with explanation and R code.

Correlogram section Data to Viz

Scatterplot matrix with ggpairs()


The ellipse package allows to build a correlogram thanks to the plotcorr() function.

First of all, you have to compute the correlation matrix of your dataset using the cor() function of R. Each correliation will be represented as an ellipse by the plotcorr() function. Color, shape and orientation depend on the correlation value.

# Libraries
library(ellipse)
library(RColorBrewer)
 
# Use of the mtcars data proposed by R
data <- cor(mtcars)
 
# Build a Pannel of 100 colors with Rcolor Brewer
my_colors <- brewer.pal(5, "Spectral")
my_colors <- colorRampPalette(my_colors)(100)
 
# Order the correlation matrix
ord <- order(data[1, ])
data_ord <- data[ord, ord]
plotcorr(data_ord , col=my_colors[data_ord*50+50] , mar=c(1,1,1,1)  )

Related chart types


Scatter
Heatmap
Correlogram
Bubble
Connected scatter
Density 2d



❤️ 10 best R tricks ❤️

👋 After crafting hundreds of R charts over 12 years, I've distilled my top 10 tips and tricks. Receive them via email! One insight per day for the next 10 days! 🔥