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



Contact

This document is a work by Yan Holtz. Any feedback is highly encouraged. You can fill an issue on Github, drop me a message on Twitter, or send an email pasting yan.holtz.data with gmail.com.

Github Twitter