<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/exploratory-data-analysis-using-r-part-i/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://blog.datazar.com/exploratory-data-analysis-using-r-part-i-17e4e8e03961?source=rss----e2c7e6e1c75--r_language"> R Language in Datazar on Medium</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<blockquote><p>The greatest value of a picture is when it forces us to notice what we never expected to see. — John W. Tukey. Exploratory Data Analysis.</p></blockquote>
<h3>Why do we use exploratory graphs in data analysis?</h3>
<ul>
<li>Understand data properties</li>
<li>Find patterns in data</li>
<li>Suggest modeling strategies</li>
<li>“Debug” analyses</li>
</ul>
<p><strong>Data –</strong>We will use the air-quality dataset available in R for our analysis.The entire project can be found <a target="_blank" rel="nofollow" href="https://www.datazar.com/project/p295cf3ce-daa2-47f1-a567-d24a13d660f0">here</a>. You can go and try it for yourself by running it on <a target="_blank" rel="nofollow" href="https://www.datazar.com/file/f48518466-c752-4179-9b0f-577545983dd6">Datazar</a>.</p>
<pre>library(datasets)<br>head(airquality)</pre>
<figure><img alt="" src="https://i0.wp.com/cdn-images-1.medium.com/max/207/1*MTNlFGvXgVyOUeOZG_2EpA.png?w=456&ssl=1" data-recalc-dims="1"></figure>
<h3>Summaries of Data</h3>
<p><strong>One dimensional Data</strong>– Univariate EDA for a quantitative variable is a way to make preliminary assessments about the population distribution of the variable using the data of the observed sample.</p>
<p>When we are dealing with a single datapoint, let’s say temperature or, wind speed, or age, the following techniques are used for the initial exploratory data analysis.</p>
<ul>
<li><strong><em>Five-number summary-</em></strong> This essantially provides information about the minimum value, 1st quartile, median, 3rd quartile and the maximum.</li>
</ul>
<pre>summary(airquality$Wind)</pre>
<figure><img alt="" src="https://i0.wp.com/cdn-images-1.medium.com/max/230/1*LuUAMdkhfcrB-AL9H0YTEQ.png?w=456&ssl=1" data-recalc-dims="1"><br>
<figcaption>Summary Of Windspeed</figcaption>
</figure>
<ul>
<li><strong><em>Boxplots</em></strong>– boxplot consists of a rectangular box bounded above and below by “hinges” that represent the quartiles Q3 and Q1 respectively, and with a horizontal “median” line through it. You can also see the upper and lower “whiskers”, and a point marking a <strong>potential </strong>“outlier”.</li>
</ul>
<blockquote><p>IQR (interquartile range) = Q3 — Q1, (the box in the plot)</p></blockquote>
<blockquote><p>whiskers = ±1.58IQR/√ n ∗ IQR, where n is the number of samples. (datapoints)</p></blockquote>
<figure><img alt="" src="https://i0.wp.com/cdn-images-1.medium.com/max/470/1*T-MLi6iMNHUQKD7pQtH0FA.png?w=456&ssl=1" data-recalc-dims="1"></figure>
<pre>boxplot(airquality$Wind~airquality$Month,col=”purple”)</pre>
<figure><img alt="" src="https://i0.wp.com/cdn-images-1.medium.com/max/589/1*ReLTzPrwSUP8-tJEEZA0TA.png?w=456&ssl=1" data-recalc-dims="1"><br>
<figcaption>Wind Speed by Month</figcaption>
</figure>
<ul>
<li><strong><em>Histograms- </em></strong>The most basic graph is the histogram, which is a bar plot in which each bar represents the frequency (count) or proportion (count/total count) of cases for a range of values. Typically the bars run vertically with the count (or proportion) axis running vertically. To manually construct a histogram, define the range of data for each bar (called a bin), count how many cases fall in each bin, and draw the bars high enough to indicate the count.</li>
</ul>
<pre>hist(airquality$Wind,col=”gold”)<br>rug(airquality$Wind)#(Optional)plots the point below in a histogram</pre>
<figure><img alt="" src="https://i0.wp.com/cdn-images-1.medium.com/max/590/1*mJehHJJPDGAqHO3rlhFf7A.png?w=456&ssl=1" data-recalc-dims="1"></figure>
<ul>
<li><strong><em>Barplot- </em></strong>A bar chart is made up of columns or rows plotted on a graph. Here is how to read a bar chart made up of columns.</li>
<li>The columns are positioned over a label that represents a categorical variable .</li>
<li>The height of the column indicates the size of the group defined by the column label.</li>
<li>A bar chart is used for when you have categories of data: Types of movies, music genres, or dog breeds.Hence, a bar chart is used (and not histogram) when we are dealing with categorical variables.</li>
</ul>
<pre>barplot(table(chickwts$feed),col = “wheat”, main=”Number Of Chickens by diet type”)</pre>
<figure><img alt="" src="https://i0.wp.com/cdn-images-1.medium.com/max/581/1*_pCSVh8K3xfbsLL69M3qOA.png?w=456&ssl=1" data-recalc-dims="1"></figure>
<p><strong>Two dimensional Data</strong>– Multivariate non-graphical EDA techniques generally show the relationship between two or more variables in the form of either cross-tabulation or statistics.</p>
<ul>
<li><strong><em>Scatter Plot-</em></strong> This essantially provides information about the minimum value, 1st quartile, median, 3rd quartile and the maximum.</li>
</ul>
<p>For two quantitative variables, the basic graphical EDA technique is the scatterplot which has one variable on the x-axis, one on the y-axis and a point for each case in your dataset. If one variable is explanatory and the other is outcome, it is a very, very strong convention to put the outcome on the y (vertical) axis.</p>
<p>One or two additional categorical variables can be accommodated on the scatterplot by encoding the additional information in the symbol type and/or color.</p>
<p><em>We will use the Males.csv dataset (present in the project on Datazar, to check whether being a part of an union impacts the salaries of young american males.</em></p>
<pre>males&lt;-read.csv(“dataset0.csv”) <br>head(males)<br>samplemales&lt;- males[1:100,] # we used first 100 rows</pre>
<pre>with(samplemales ,plot(exper,wage, col= union)) <br>#union is a categorical variable represented by color</pre>
<figure><img alt="" src="https://i0.wp.com/cdn-images-1.medium.com/max/614/1*SREpdXErPg0sOT6X4e5B5w.png?w=456&ssl=1" data-recalc-dims="1"><br>
<figcaption>Scatter plot to represent age vs experience (the color represent whether the employee is a part of an union)</figcaption>
</figure>
<p><em>We can also use multiple scatter plots to understand better, whether being part of an union impacts an employees salary.</em></p>
<figure><img alt="" src="https://i0.wp.com/cdn-images-1.medium.com/max/605/1*igEWxm2G8CId84gNqE5k-g.png?w=456&ssl=1" data-recalc-dims="1"></figure>
<p>We can see that, most employees are not part of an union and they tend to earn more than employees who are a part of an union.Correlation doesn’t always mean causation, as it might be the case, the high paying industries do not allow their employees to form unions.</p>
<p><em>In a nutshell: You should always perform appropriate EDA before further analysis of your data</em></p>
<p>Lastly, I wish you all a merry Christmas and a very happy new year. I will come back with the next edition of EDA in New Year. Till then, happy modeling!</p>
<p><img height="1" width="1" src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17e4e8e03961"><br>
<hr>
<p><a target="_blank" rel="nofollow" href="https://blog.datazar.com/exploratory-data-analysis-using-r-part-i-17e4e8e03961">Exploratory Data Analysis Using R (Part-I)</a> was originally published in <a target="_blank" rel="nofollow" href="https://blog.datazar.com/">Datazar</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>
<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://blog.datazar.com/exploratory-data-analysis-using-r-part-i-17e4e8e03961?source=rss----e2c7e6e1c75--r_language"> R Language in Datazar on Medium</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/FxvlfD7KK8c"></a></div>