The package “corrplot” is used for graphical display of a correlation matrix. The features in this package can be used to customise the correlation matrix plot. We can choose text labels, colour labels, layout, etc. Also there are options available for matrix reordering.

Install and load package corrplot

install.packages("corrplot")
library(corrplot)
MICA<-read.csv("Motor Insurance claim amount.csv",header=TRUE)
head(MICA)
  vehage   CC Length Weight claimamt
1      4 1495   4250   1023  72000.0
2      2 1061   3495    875  72000.0
3      2 1405   3675    980  50400.0
4      7 1298   4090    930  39960.0
5      2 1495   4250   1023 106800.0
6      1 1086   3565    854  69592.8
c<-cor(MICA)
c
             vehage        CC    Length    Weight   claimamt
vehage    1.0000000 0.1282000 0.1882112 0.1402555 -0.6009692
CC        0.1282000 1.0000000 0.8041008 0.9055685  0.4580953
Length    0.1882112 0.8041008 1.0000000 0.8264651  0.4780824
Weight    0.1402555 0.9055685 0.8264651 1.0000000  0.4169866
claimamt -0.6009692 0.4580953 0.4780824 0.4169866  1.0000000

Visualizing plots

corrplot(c,method="circle")

Positive correlations are displayed in blue and negative correlations in red color. Color intensity and the size of the circle are proportional to the correlation coefficients.

There are seven visualization methods in corrplot package, namely circle, square, ellipse, number, shade, color and pie

corrplot(c,method="number")

Layout

There are three types of layout

corrplot(c,method = "square", type = "upper")

corrplot.mixed() is a function used to display mixed visualization style.

lower= specifies the visualization method for the lower triangular correlation matrix.

upper= specifies the visualization method for the upper triangular correlation matrix.

corrplot.mixed(c,lower = "number", upper = "ellipse" )

We can also specify the colour and font size of the number using lower.col=and number.cex=

corrplot.mixed(c, lower.col = "black", number.cex = .7)

Reordering of Correlation Matrix

The correlation matrix can be reordered according to the correlation coefficient. This is important to identify the hidden structure and pattern in the matrix.

There are four methods for reordering in corrplot

corrplot(c, order = "hclust")