An Introduction to corrplot package

Introduction

The corrplot package is a graphical display of a correlation matrix, confidence interval. It also contains some algorithms to do matrix reordering. In addition, corrplot is good at details, including choosing color, text labels, color labels, layout, etc.

Visualization Methods

There are seven visualization methods (parameter method) in corrplot package, named "circle", "square", "ellipse", "number", "shade", "color", "pie".

library(corrplot)
M <- cor(mtcars)
corrplot(M, method = "circle")

plot of chunk methods

corrplot(M, method = "square")

plot of chunk methods

corrplot(M, method = "ellipse")

plot of chunk methods

corrplot(M, method = "number")

plot of chunk methods

corrplot(M, method = "shade")

plot of chunk methods

corrplot(M, method = "color")

plot of chunk methods

corrplot(M, method = "pie")

plot of chunk methods

Layout

There are three layout types (parameter type), named "full" (default), "upper" or "lower", display full matrix, lower triangular or upper triangular matrix.

corrplot(M, type = "upper")

plot of chunk layout

corrplot(M, type = "lower")

plot of chunk layout

corrplot.mixed() is a wrapped function for mixed visualization style.

corrplot.mixed(M)

plot of chunk mixed

corrplot.mixed(M, lower = "ellipse", upper = "circle")

plot of chunk mixed

corrplot.mixed(M, lower = "square", upper = "circle")

plot of chunk mixed

Reorder A Correlation Matrix

Matrix reorder is very important for mining the hiden structure and pattern in the matrix. There are four methods in corrplot (parameter order), named "AOE", "FPC", "hclust", "alphabet". More algorithms can be found in seriation package.

You can also reorder the matrix “manually” via function corrMatOrder().

\[ a_i = \begin{cases} \tan (e_{i2}/e_{i1}), & \text{if $e_{i1}>0$;} \newline \tan (e_{i2}/e_{i1}) + \pi, & \text{otherwise.} \end{cases} \]

where \(e_1\) and \(e_2\) are the largest two eigenvalues of the correlation matrix. See Michael Friendly (2002) for details.

corrplot(M, order = "AOE")