Visualize correlation matrix using symnum function
<!--====================== start from here when you copy to sthda================-->
<div id="rdoc">
<div id="TOC">
<ul>
<li>Graph of correlation matrix using symnum function</li>
<li>Conclusions</li>
<li>Infos</li>
</ul>
</div>
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.
<div class="block">
<i class="fa - fa-cogs fa-4x valign_middle"></i> Note that online software is also available here to compute correlation matrix and to plot a correlogram without any installation.
</div>
<div id="graph-of-correlation-matrix-using-symnum-function" class="section level1">
<h1>Graph of correlation matrix using symnum function</h1>
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 :
<pre class="r"><code>symnum(x, cutpoints = c(0.3, 0.6, 0.8, 0.9, 0.95),
symbols = c(" ", ".", ",", "+", "*", "B"))</code>[/pre]
- 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 :
<pre class="r"><code>## Correlation matrix
corMat<-cor(mtcars)
head(round(corMat,2))</code>[/pre]
<code> 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</code>
<pre class="r"><code>## Correlation graph for visualization
## abbr.colnames=FALSE to avoid abbreviation of column names
symnum(corMat, abbr.colnames=FALSE)</code>[/pre]
<code> 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</code>
</div>
<div id="conclusions" class="section level1">
<h1>Conclusions</h1>
<div class="block">
One of the easy way to visualize correlation matrix in R is to use the symnum() R function.
</div>
</div>
<div id="infos" class="section level1">
<h1>Infos</h1>
<pre class="warning"><code>This analysis was performed using R (ver. 3.1.0).</code>[/pre]
</div>
<script>jQuery(document).ready(function () {
jQuery('h1').addClass('wiki_paragraph1');
jQuery('h2').addClass('wiki_paragraph2');
jQuery('h3').addClass('wiki_paragraph3');
jQuery('h4').addClass('wiki_paragraph4');
});//add phpboost class to header</script>
<style>.content{padding:0px;}</style>
</div><!--end rdoc-->
<!--====================== stop here when you copy to sthda================-->
[/html]
Show me some love with the like buttons below... Thank you and please don't forget to share and comment below!!
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!
Recommended for You!
Recommended for you
This section contains the best data science and self-development resources to help you on your path.
Books - Data Science
Our Books
- Practical Guide to Cluster Analysis in R by A. Kassambara (Datanovia)
- Practical Guide To Principal Component Methods in R by A. Kassambara (Datanovia)
- Machine Learning Essentials: Practical Guide in R by A. Kassambara (Datanovia)
- R Graphics Essentials for Great Data Visualization by A. Kassambara (Datanovia)
- GGPlot2 Essentials for Great Data Visualization in R by A. Kassambara (Datanovia)
- Network Analysis and Visualization in R by A. Kassambara (Datanovia)
- Practical Statistics in R for Comparing Groups: Numerical Variables by A. Kassambara (Datanovia)
- Inter-Rater Reliability Essentials: Practical Guide in R by A. Kassambara (Datanovia)
Others
- R for Data Science: Import, Tidy, Transform, Visualize, and Model Data by Hadley Wickham & Garrett Grolemund
- Hands-On Machine Learning with Scikit-Learn, Keras, and TensorFlow: Concepts, Tools, and Techniques to Build Intelligent Systems by Aurelien Géron
- Practical Statistics for Data Scientists: 50 Essential Concepts by Peter Bruce & Andrew Bruce
- Hands-On Programming with R: Write Your Own Functions And Simulations by Garrett Grolemund & Hadley Wickham
- An Introduction to Statistical Learning: with Applications in R by Gareth James et al.
- Deep Learning with R by François Chollet & J.J. Allaire
- Deep Learning with Python by François Chollet
Click to follow us on Facebook :
Comment this article by clicking on "Discussion" button (top-right position of this page)