Visualize correlation matrix using symnum function

This article describes how to make a graph of correlation matrix in R. The R symnum() function is used. It takes the correlation table as an argument. The result is a table in which correlation coefficients are replaced by symbols according to the degree of correlation.

Note that online software is also available here to compute correlation matrix and to plot a correlogram without any installation.

Graph of correlation matrix using symnum function

The R function symnum can be used to easily highlight the highly correlated variables. It replaces correlation coefficients by symbols according to the value.

The simplified format of the function is :

symnum(x, cutpoints = c(0.3, 0.6, 0.8, 0.9, 0.95),
       symbols = c(" ", ".", ",", "+", "*", "B"))

- x is the correlation matrix to visualize - cutpoints : correlation coefficient cutpoints. The correlation coefficients between 0 and 0.3 are replaced by a space (" “); correlation coefficients between 0.3 and 0.6 are replace by”.“; etc … - symbols : the symbols to use.

The following R code performs a correlation analysis and displays a graph of the correlation matrix :

## Correlation matrix
corMat<-cor(mtcars)
head(round(corMat,2))
       mpg   cyl  disp    hp  drat    wt  qsec    vs    am  gear  carb
mpg   1.00 -0.85 -0.85 -0.78  0.68 -0.87  0.42  0.66  0.60  0.48 -0.55
cyl  -0.85  1.00  0.90  0.83 -0.70  0.78 -0.59 -0.81 -0.52 -0.49  0.53
disp -0.85  0.90  1.00  0.79 -0.71  0.89 -0.43 -0.71 -0.59 -0.56  0.39
hp   -0.78  0.83  0.79  1.00 -0.45  0.66 -0.71 -0.72 -0.24 -0.13  0.75
drat  0.68 -0.70 -0.71 -0.45  1.00 -0.71  0.09  0.44  0.71  0.70 -0.09
wt   -0.87  0.78  0.89  0.66 -0.71  1.00 -0.17 -0.55 -0.69 -0.58  0.43
## Correlation graph for visualization
## abbr.colnames=FALSE to avoid abbreviation of column names
symnum(corMat, abbr.colnames=FALSE)
     mpg cyl disp hp drat wt qsec vs am gear carb
mpg  1                                           
cyl  +   1                                       
disp +   *   1                                   
hp   ,   +   ,    1                              
drat ,   ,   ,    .  1                           
wt   +   ,   +    ,  ,    1                      
qsec .   .   .    ,          1                   
vs   ,   +   ,    ,  .    .  ,    1              
am   .   .   .       ,    ,          1           
gear .   .   .       ,    .          ,  1        
carb .   .   .    ,       .  ,    .          1   
attr(,"legend")
[1] 0 ' ' 0.3 '.' 0.6 ',' 0.8 '+' 0.9 '*' 0.95 'B' 1

Conclusions

One of the easy way to visualize correlation matrix in R is to use the symnum() R function.

Infos

This analysis was performed using R (ver. 3.1.0).

Enjoyed this article? I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Twitter, Facebook or Linked In.

Show me some love with the like buttons below... Thank you and please don't forget to share and comment below!!
Avez vous aimé cet article? Je vous serais très reconnaissant si vous aidiez à sa diffusion en l'envoyant par courriel à un ami ou en le partageant sur Twitter, Facebook ou Linked In.

Montrez-moi un peu d'amour avec les like ci-dessous ... Merci et n'oubliez pas, s'il vous plaît, de partager et de commenter ci-dessous!






This page has been seen 5845 times