<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/anscombes-quartet-1980s-edition/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://methodmatters.blogspot.com/2018/01/anscombes-quartet-1980s-edition.html"> Method Matters</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>In this post, I’ll describe a fun visualization of Anscombe’s quartet I whipped up recently.</p>
<p>If you aren’t familiar with Anscombe’s quartet, here’s a brief description from its <a rel="nofollow" href="https://en.wikipedia.org/wiki/Anscombe%27s_quartet" target="_blank">Wikipedia entry</a>: “<i>Anscombe’s quartet comprises four datasets that have nearly identical simple descriptive statistics, yet appear very different when graphed. Each dataset consists of eleven (x,y) points. They were constructed in 1973 by the statistician Francis Anscombe to demonstrate both the importance of graphing data before analyzing it and the effect of outliers on statistical properties. He described the article as being intended to counter the impression among statisticians that ‘numerical calculations are exact, but graphs are rough.’</i> “</p>
<p>In essence, there are 4 different datasets with quite different patterns in the data. Fitting a linear regression model through each dataset yields (nearly) identical regression coefficients, while graphing the data makes it clear that the underlying patterns are very different. What’s amazing to me is how these simple data sets (and accompanying graphs) make immediately intuitive the importance of data visualization, and drive home the point of how well-constructed graphs can help the analyst understand the data he or she is working with.  </p>
<p>The <a rel="nofollow" href="https://stat.ethz.ch/R-manual/R-devel/library/datasets/html/anscombe.html" target="_blank">Anscombe data</a> are included in base R, and these data (and R, of course!) are used to produce the <a rel="nofollow" href="https://commons.wikimedia.org/wiki/File:Anscombe%27s_quartet_3.svg" target="_blank">plot that accompanies the Wikipedia entry</a> on Anscombe’s quartet.</p>
<p>Because <a rel="nofollow" href="https://www.theguardian.com/tv-and-radio/2017/feb/18/stranger-things-why-tv-is-obsessed-with-the-80s" target="_blank">the 1980’s</a> <a rel="nofollow" href="https://www.nytimes.com/2016/04/21/fashion/dont-you-forget-about-me-the-formerly-irredeemable-80s-return.html" target="_blank">are back</a>, I decided to make a visualization of Anscombe’s quartet using the <i>like-most-totally-rad</i> 1980’s graphing elements I could come up with. I was aided with the colors by a <a rel="nofollow" href="http://www.colourlovers.com/palette/1918087/80s_Neon_Flashback" target="_blank">number of</a> <a rel="nofollow" href="http://www.colourlovers.com/palette/1533132/That_80s_Palette" target="_blank">graphic design</a> <a rel="nofollow" href="http://www.colourlovers.com/palette/1786593/Hot_80s_Nights" target="_blank">palettes</a> with accompanying hex codes. I used the excellent <a rel="nofollow" href="https://cran.r-project.org/web/packages/showtext/vignettes/introduction.html" target="_blank"><b>showtext</b></a> package for the 1980’s font, which comes from the Google font “<a rel="nofollow" href="https://fonts.google.com/specimen/Press+Start+2P?selection.family=Press+Start+2P" target="_blank">Press Start 2P</a>.” (Note, if you’re reproducing the graph at home, the fonts won’t show properly in RStudio. Run the code in the standalone R program and everything works like a charm). I had to tweak a number of <a rel="nofollow" href="https://stat.ethz.ch/R-manual/R-devel/library/graphics/html/par.html" target="_blank">graphical parameters</a> in order to get the layout right, but in the end I’m quite pleased with the result.</p>
<p></p>
<div><b>The Code</b></div>
<p></p>
<pre><span># showtext library to get 1980's font</span><br><span># &quot;Press Start 2P&quot;</span><br>library(<span>showtext</span>)<br><span># add the font from Google fonts</span><br>font.add.google(<span>&quot;Press Start 2P&quot;</span>, <span>&quot;start2p&quot;</span>)<br><br><br>png(<span>&quot;C:<span>\\</span>Directory<span>\\</span>Anscombe_80s.png&quot;</span>, <br>    <span>width</span>=<span>11</span>,<span>height</span>=<span>8</span>, <span>units</span>=<span>'in'</span>, <span>res</span>=<span>600</span>)<br><br>showtext.begin()<br><span>op</span> <span>&lt;-</span> par(<span>las</span>=<span>1</span>, <span>mfrow</span>=c(<span>2</span>,<span>2</span>), <span>mar</span>=<span>1.5</span><span>+</span>c(<span>4</span>,<span>4</span>,.<span>5</span>,<span>1</span>), <span>oma</span>=c(<span>0</span>,<span>0</span>,<span>5</span>,<span>0</span>),<br>          <span>lab</span>=c(<span>6</span>,<span>6</span>,<span>7</span>), <span>cex.lab</span>=<span>12.0</span>, <span>cex.axis</span>=<span>5</span>, <span>mgp</span>=c(<span>3</span>,<span>1</span>,<span>0</span>), <span>bg</span> <span>=</span> <span>'black'</span>,<br>          <span>col.axis</span> <span>=</span> <span>'#F2CC00'</span>, <span>col.lab</span> <span>=</span> <span>'#A10EEC'</span>, <span>family</span> <span>=</span> <span>'start2p'</span>) <br><span>ff</span> <span>&lt;-</span> <span>y</span> <span>~</span> <span>x</span><br><span>for</span>(<span>i</span> <span>in</span> <span>1</span><span>:</span><span>4</span>) {<br>  <span>ff</span>[[<span>2</span>]] <span>&lt;-</span> as.name(paste(<span>&quot;y&quot;</span>, <span>i</span>, <span>sep</span>=<span>&quot;&quot;</span>))<br>  <span>ff</span>[[<span>3</span>]] <span>&lt;-</span> as.name(paste(<span>&quot;x&quot;</span>, <span>i</span>, <span>sep</span>=<span>&quot;&quot;</span>))<br>  <span>lmi</span> <span>&lt;-</span> lm(<span>ff</span>, <span>data</span>= <span>anscombe</span>)<br>  <span>xl</span> <span>&lt;-</span> substitute(expression(<span>x</span>[<span>i</span>]), list(<span>i</span>=<span>i</span>))  <br>  <span>yl</span> <span>&lt;-</span> substitute(expression(<span>y</span>[<span>i</span>]), list(<span>i</span>=<span>i</span>))<br>  plot(<span>ff</span>, <span>data</span>=<span>anscombe</span>, <span>col</span>=<span>&quot;#490E61&quot;</span>, <span>pch</span>=<span>21</span>, <span>cex</span>=<span>2.4</span>, <span>bg</span> <span>=</span> <span>&quot;#32FA05&quot;</span>, <br>       <span>xlim</span>=c(<span>3</span>,<span>19</span>), <span>ylim</span>=c(<span>3</span>,<span>13</span>)<br>       , <span>xlab</span>=eval(<span>xl</span>), <span>ylab</span>=<span>yl</span>, <br>       <span>family</span> <span>=</span> <span>'start2p'</span> <br>  )  <br>  abline(<span>lmi</span>, <span>col</span>=<span>&quot;#FA056F&quot;</span>, <span>lwd</span> <span>=</span> <span>5</span>)<br>  axis(<span>1</span>, <span>col</span> <span>=</span> <span>'#FA1505'</span>)<br>  axis(<span>2</span>, <span>col</span> <span>=</span> <span>'#FA1505'</span>)<br>  box(<span>col</span>=<span>&quot;#FA1505&quot;</span>)<br>}<br>mtext(<span>&quot;Anscombe's Quartet&quot;</span>, <span>outer</span> <span>=</span> <span>TRUE</span>, <br><span>cex</span> <span>=</span> <span>20</span>, <span>family</span> <span>=</span> <span>'start2p'</span>, <span>col</span>=<span>&quot;#FA1505&quot;</span>) <br>showtext.end()<br><br>dev.off()<br><br></pre>
<div><b>The Plot</b>
</div>
<p></p>
<div><a rel="nofollow" href="https://i2.wp.com/3.bp.blogspot.com/-rT7fJEJlfuk/WaJ-rUtI02I/AAAAAAAAAXY/b6KIYqaDvFko9zhdmQuKy8YUjVKw1B1dQCLcBGAs/s1600/anscombe_blog.png?ssl=1" target="_blank"><img border="0" data-original-height="1164" src="https://i2.wp.com/3.bp.blogspot.com/-rT7fJEJlfuk/WaJ-rUtI02I/AAAAAAAAAXY/b6KIYqaDvFko9zhdmQuKy8YUjVKw1B1dQCLcBGAs/s1600/anscombe_blog.png?resize=450%2C1164&ssl=1" data-recalc-dims="1" data-original-width="450"></a></div>
<div><b>Conclusion</b></div>
<p>In this post, I used data available in R to make a 1980’s-themed version of the Anscombe quartet graphs. The main visual elements I manipulated were the colors and the fonts. R’s wonderful and flexible plotting capabilities (here using base R!) made it very straightforward to edit every detail of the graph to achieve the desired retro-kitsch aesthetic.</p>
<p>OK, so maybe this isn’t the most serious use of R for data analysis and visualization. There are doubtless more important business cases and analytical problems to solve. Nevertheless, this was super fun to do. Data analysis (or data science, or whatever you’d like to call it) is a field in which there are countless ways to be creative with data. It’s not always easy to bring this type of creativity to every applied project, but this blog is a place where I can do any crazy thing I set my mind to and just have fun. Judging by that standard, I think this project was a success.</p>
<p><i>Coming Up Next </i></p>
<p>In the next post, I’ll do something a little bit different with data. Rather than doing data analysis, I’ll describe a project in which I used Python to manage and edit meta-data (ID3 tags) in mp3 files. Stay tuned!</p>
<p></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="http://methodmatters.blogspot.com/2018/01/anscombes-quartet-1980s-edition.html"> Method Matters</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 rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/Ku3FjpDRA3g" height="1"></a></div>