<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/infographic-style-charts-using-the-r-waffle-package/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://nsaunders.wordpress.com/2017/09/08/infographic-style-charts-using-the-r-waffle-package/"> R – What You're Doing Is Rather Desperate</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Infographics. I’ve seen good examples. I’ve seen more bad examples. In general, I prefer a good chart to an infographic. That said, there’s a “genre” of infographic that I do think is useful, which I’ll call “if X were 100 Y”. A good example: <a rel="nofollow" href="http://floda31.com/2011/05/if-the-world-were-100-people/" target="_blank">if the world were 100 people</a>.</p>
<p>That method of showing proportions has been called a <em>waffle chart</em> and for extra “infographic-i-ness”, the squares can be replaced by icons. You want to do this using R? Of course you do. Here’s how.<br>
<span></span><br>
There’s not much more here than you’ll find at the Github home of the R packages, <a rel="nofollow" href="https://github.com/hrbrmstr/waffle" target="_blank">waffle</a> and <a rel="nofollow" href="https://github.com/wch/extrafont" target="_blank">extrafont</a>. I’ve just made it a little more step-by-step.</p>
<p><strong>1. Install the R packages</strong><br>
You need <em>waffle</em> to create waffle charts and <em>extrafont</em> to use icons in the charts.</p>
<pre>
install.packages(c(&quot;waffle&quot;, &quot;extrafont&quot;))

library(waffle)
library(extrafont)
</pre>
<p><strong>2. Install Font Awesome</strong><br>
The icons that <em>waffle</em> can use are supplied by <a rel="nofollow" href="http://fontawesome.io/" target="_blank">Font Awesome</a>.</p>
<p>Download the zip file by clicking the Download link at their website. You may want to check out the paid option later but for now, just select the free download.</p>
<p>Unzip the file and navigate to the <em>fonts</em> directory. To install the font, use the file named <code>fontawesome-webfont.ttf</code>. For Windows or Mac OS X users, installation is as simple as double-clicking the file and choosing “Install”. I haven’t done this under Linux for a while, it may even be the same procedure these days.</p>
<p><strong>3. Import and register fonts</strong><br>
In R, fonts have to be imported to the <em>extrafont</em> database. You need to do this whenever a new font is installed that you want to use in R.</p>
<pre>
font_import()

# check that Font Awesome is imported
fonts()[grep(&quot;Awesome&quot;, fonts())]
# [1] &quot;FontAwesome&quot;
</pre>
<p>If you run <code>font_import()</code> in a session, you need to register the fonts with the R output device. Otherwise, this occurs when the package is loaded. If you’re using the Windows OS and want to plot to the screen in RStudio, an additional argument is required:</p>
<pre>
# this should be fine for Mac OSX
loadfonts()
# use this if things look odd in RStudio under Windows
loadfonts(device = &quot;win&quot;)
</pre>
<p><strong>4. Create charts</strong><br>
Now we are ready to waffle. First, your basic waffle chart. The default colours are Colour Brewer “Set2”.</p>
<pre>
waffle(c(50, 30, 15, 5), rows = 5, title = &quot;Your basic waffle chart&quot;)
</pre>
<p><a rel="nofollow" href="https://nsaunders.wordpress.com/?attachment_id=4939" target="_blank"><img data-orig-file="https://nsaunders.files.wordpress.com/2017/09/waffle1.png" data-orig-size="745,523" data-medium-file="https://nsaunders.files.wordpress.com/2017/09/waffle1.png?w=300" data-attachment-id="4939" data-image-meta="{" data-image-description="" src="https://nsaunders.files.wordpress.com/2017/09/waffle1.png?w=1024&h=720&fit=456%2C456" data-permalink="https://nsaunders.wordpress.com/2017/09/08/infographic-style-charts-using-the-r-waffle-package/waffle1/" data-large-file="https://nsaunders.files.wordpress.com/2017/09/waffle1.png?w=745" alt="" data-image-title="waffle1" sizes="(max-width: 745px) 100vw, 745px" data-comments-opened="1" class="wp-image-4939" data-recalc-dims="1"></a></p>
<p>Next, using icons. You can browse or search for available icon names <a rel="nofollow" href="http://fontawesome.io/icons/" target="_blank">on this page</a>. You may need to fiddle with the size.</p>
<pre>
waffle(c(50, 30, 15, 5), rows = 5, use_glyph = &quot;child&quot;, glyph_size = 6, 
title = &quot;Look I made an infographic using R!&quot;)
</pre>
<p><a rel="nofollow" href="https://nsaunders.wordpress.com/?attachment_id=4942" target="_blank"><img data-orig-file="https://nsaunders.files.wordpress.com/2017/09/waffle2.png" data-orig-size="745,523" data-medium-file="https://nsaunders.files.wordpress.com/2017/09/waffle2.png?w=300" data-attachment-id="4942" data-image-meta="{" data-image-description="" src="https://nsaunders.files.wordpress.com/2017/09/waffle2.png?w=1024&h=720&fit=456%2C456" data-permalink="https://nsaunders.wordpress.com/2017/09/08/infographic-style-charts-using-the-r-waffle-package/waffle2/" data-large-file="https://nsaunders.files.wordpress.com/2017/09/waffle2.png?w=745" alt="" data-image-title="waffle2" sizes="(max-width: 745px) 100vw, 745px" data-comments-opened="1" class="wp-image-4942" data-recalc-dims="1"></a></p>
<p>You can use the <code>iron()</code> function to append waffle charts, which might be useful in comparisons. Here’s some made-up data involving some aspect of cars in two unnamed countries:</p>
<pre>
iron(
  waffle(c(no = 80, yes = 20), rows = 5, use_glyph = &quot;car&quot;, glyph_size = 6, 
         colors = c(&quot;#c7d4b6&quot;, &quot;#a3aabd&quot;), title = &quot;Country A&quot;),
  waffle(c(no = 70, yes = 30), rows = 5, use_glyph = &quot;car&quot;, glyph_size = 6,
         colors = c(&quot;#c7d4b6&quot;, &quot;#a3aabd&quot;), title = &quot;Country B&quot;)
)
</pre>
<p><a rel="nofollow" href="https://nsaunders.wordpress.com/?attachment_id=4945" target="_blank"><img data-orig-file="https://nsaunders.files.wordpress.com/2017/09/waffle3.png" data-orig-size="745,523" data-medium-file="https://nsaunders.files.wordpress.com/2017/09/waffle3.png?w=300" data-attachment-id="4945" data-image-meta="{" data-image-description="" src="https://nsaunders.files.wordpress.com/2017/09/waffle3.png?w=1024&h=720&fit=456%2C456" data-permalink="https://nsaunders.wordpress.com/2017/09/08/infographic-style-charts-using-the-r-waffle-package/waffle3/" data-large-file="https://nsaunders.files.wordpress.com/2017/09/waffle3.png?w=745" alt="" data-image-title="waffle3" sizes="(max-width: 745px) 100vw, 745px" data-comments-opened="1" class="wp-image-4945" data-recalc-dims="1"></a></p>
<p><strong>Conclusion</strong><br>
That’s it, more or less. Are the icons any more effective than the squares? In certain settings, perhaps. You be the judge.</p>
<p>Filed under: <a rel="nofollow" href="https://nsaunders.wordpress.com/category/statistics/r/" target="_blank">R</a>, <a rel="nofollow" href="https://nsaunders.wordpress.com/category/statistics/" target="_blank">statistics</a> Tagged: <a rel="nofollow" href="https://nsaunders.wordpress.com/tag/packages/" target="_blank">packages</a>, <a rel="nofollow" href="https://nsaunders.wordpress.com/tag/rstats/" target="_blank">rstats</a>, <a rel="nofollow" href="https://nsaunders.wordpress.com/tag/visualization/" target="_blank">visualization</a>, <a rel="nofollow" href="https://nsaunders.wordpress.com/tag/waffle/" target="_blank">waffle</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nsaunders.wordpress.com/4937/" target="_blank"><img border="0" alt="" src="http://feeds.wordpress.com/1.0/comments/nsaunders.wordpress.com/4937/"></a> <img border="0" alt="" src="https://i1.wp.com/pixel.wp.com/b.gif?resize=1%2C1&ssl=1" data-recalc-dims="1"></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://nsaunders.wordpress.com/2017/09/08/infographic-style-charts-using-the-r-waffle-package/"> R – What You're Doing Is Rather Desperate</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 alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/S4Ywf_GvdZ8" height="1"></a></div>