<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/nice-graphic-are-they-taking-the-p/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://nsaunders.wordpress.com/2017/02/04/nice-graphic-are-they-taking-the-p/"> 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>Yes, it started with a tweet:</p>
<div>
<blockquote data-width="550" class="twitter-tweet">
<p dir="ltr" lang="en">Nice graphic on urine components via <a target="_blank" rel="nofollow" href="https://t.co/sfuXNB02sF">https://t.co/sfuXNB02sF</a> <a target="_blank" rel="nofollow" href="https://t.co/vhVLahQ8su">pic.twitter.com/vhVLahQ8su</a></p>
<p>— Metabolomics (@metabolomics) <a target="_blank" rel="nofollow" href="https://twitter.com/metabolomics/status/826374545279836160">January 31, 2017</a></p>
</blockquote>
<p></div>
<p>By what measure is this a “nice graphic”? First, the JPEG itself is low-quality. Second, it contains spelling and numerical errors (more on that later). And third…do I have to spell this out…those are <em>3D pie charts</em>.</p>
<p>Can it be fixed?<br>
<span></span></p>
<p>So far as I know, there isn’t a tool to generate data by extracting labels from images, so I sat down and typed in the numbers manually. <a target="_blank" rel="nofollow" href="https://drive.google.com/file/d/0B--guWzPjOLJN1V0eWZCRGxnVFE/view?usp=sharing">Here they are</a> for download. The top and bottom pie charts are identified by “all” and “other”, respectively.</p>
<p>Better make sure those percentages total 100, before we get into charts.</p>
<pre>
library(ggplot2)
library(dplyr)
library(readr)

urine1 &lt;- read_csv(&quot;urine1.csv&quot;, col_names = FALSE)
colnames(urine1) &lt;- c(&quot;component&quot;, &quot;all_other&quot;, &quot;percent&quot;)

# top chart - good!
urine1 %>% filter(all_other == &quot;all&quot;) %>% summarise(total = sum(percent)) %>% glimpse()

# Observations: 1
# Variables: 1
# $ total &lt;dbl> 99.9

# bottom chart - not good
urine1 %>% filter(all_other == &quot;other&quot;) %>% summarise(total = sum(percent)) %>% glimpse()

# Observations: 1
# Variables: 1
# $ total &lt;dbl> 113.61
</pre>
<p>Slices in the bottom chart sum to 113.61%. Problem. Not being an expert in urine composition I have no idea which figures might be incorrect, so I’ll just have to discard that data. However, on the subject of accuracy, I do know that it is <em>lysozyme</em> not <em>lyzozyme</em> and <em>immunoglobulins</em> not <em>immunoglobulines</em>.</p>
<p>Back to the top chart. Why are pie charts bad? Because we are poor at visually assessing relative areas (but good at assessing relative heights). And why are 3D pie charts bad? Because they are nothing but a gimmick, adding nothing to the visualisation and in fact, distorting it in the attempt to render perspective. The commonly-heard rejoinder is “but business people like them.” Well, that doesn’t make them right.</p>
<p>So we could try a bar chart, sorted by value.</p>
<pre>
urine1 %>% filter(all_other == &quot;all&quot;) %>% 
  ggplot(aes(reorder(component, -percent), percent)) + 
  geom_col(fill = &quot;skyblue3&quot;) + theme_bw() + 
  labs(x = &quot;component&quot;, y = &quot;percent&quot;, title = &quot;Composition of human urine&quot;, subtitle = &quot;50 g  dry weight / L&quot;)
</pre>
<p><a target="_blank" rel="nofollow" href="https://nsaunders.wordpress.com/2017/02/04/nice-graphic-are-they-taking-the-p/urine1-1/"><img sizes="(max-width: 1024px) 100vw, 1024px" data-image-description="" data-orig-file="https://nsaunders.files.wordpress.com/2017/02/urine1-1.png" data-orig-size="1098,804" data-image-title="urine1-1" data-comments-opened="1" class="wp-image-4677" data-recalc-dims="1" data-attachment-id="4677" data-permalink="https://nsaunders.wordpress.com/2017/02/04/nice-graphic-are-they-taking-the-p/urine1-1/" alt="urine1-1" data-medium-file="https://nsaunders.files.wordpress.com/2017/02/urine1-1.png?w=300" data-large-file="https://nsaunders.files.wordpress.com/2017/02/urine1-1.png?w=1024" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="https://i0.wp.com/nsaunders.files.wordpress.com/2017/02/urine1-1.png?fit=456%2C456&ssl=1"></a></p>
<p>Which is OK: it makes it easy to see and compare the relative proportion of each component. There’s a lot of white space though. We could stack the bars, but that would create problems in choosing a colour palette. So here’s another alternative: a treemap, created using the rather wonderful <a target="_blank" rel="nofollow" href="http://jkunst.com/r/presenting-highcharter/">highcharter</a> package.</p>
<pre>
library(treemap)
library(highcharter)

urine1_tm &lt;- treemap(filter(urine1, all_other == &quot;all&quot;), index = &quot;component&quot;, vSize = &quot;percent&quot;, palette = &quot;Spectral&quot;)
urine1_tmhc &lt;- highchart() %>% hc_add_series_treemap(urine1_tm, name = &quot;urine&quot;, layoutAlgorithm = &quot;squarified&quot;) %>% 
  hc_title(text = &quot;Composition of human urine (50 g  dry weight / L)&quot;)
</pre>
<p>Result: a <a target="_blank" rel="nofollow" href="http://rpubs.com/neilfws/247064">nice interactive chart</a>. Published straight to RPubs from the RStudio viewer pane, by the way. RStudio is just great. Here’s the non-interactive screenshot.</p>
<p><a target="_blank" rel="nofollow" href="https://nsaunders.wordpress.com/2017/02/04/nice-graphic-are-they-taking-the-p/urine1-2/"><img sizes="(max-width: 1024px) 100vw, 1024px" data-image-description="" data-orig-file="https://nsaunders.files.wordpress.com/2017/02/urine1-2.png" data-orig-size="2194,1608" data-image-title="urine1-2" data-comments-opened="1" class="wp-image-4680" data-recalc-dims="1" data-attachment-id="4680" data-permalink="https://nsaunders.wordpress.com/2017/02/04/nice-graphic-are-they-taking-the-p/urine1-2/" alt="urine1-2" data-medium-file="https://nsaunders.files.wordpress.com/2017/02/urine1-2.png?w=300" data-large-file="https://nsaunders.files.wordpress.com/2017/02/urine1-2.png?w=1024" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="https://i2.wp.com/nsaunders.files.wordpress.com/2017/02/urine1-2.png?fit=456%2C456&ssl=1"></a></p>
<p>I’d suggest that if you must present proportions by area, this is a much nicer way to do it.</p>
<p>In summary then:</p>
<ul>
<li>pie charts bad</li>
<li>3D pie charts awful</li>
<li>columns functional, if not always compelling</li>
<li>so many other wonderful tools out there to visualise data than the tired old options</li>
</ul>
<p>Filed under: <a target="_blank" rel="nofollow" href="https://nsaunders.wordpress.com/category/statistics/r/">R</a>, <a target="_blank" rel="nofollow" href="https://nsaunders.wordpress.com/category/statistics/">statistics</a> Tagged: <a target="_blank" rel="nofollow" href="https://nsaunders.wordpress.com/tag/charts/">charts</a>, <a target="_blank" rel="nofollow" href="https://nsaunders.wordpress.com/tag/data/">data</a>, <a target="_blank" rel="nofollow" href="https://nsaunders.wordpress.com/tag/visualisation/">visualisation</a> <a target="_blank" rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nsaunders.wordpress.com/4667/"><img alt="" src="http://feeds.wordpress.com/1.0/comments/nsaunders.wordpress.com/4667/" border="0"></a> <img alt="" src="https://i1.wp.com/pixel.wp.com/b.gif?resize=1%2C1&ssl=1" border="0" 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/02/04/nice-graphic-are-they-taking-the-p/"> 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 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/-i7Zwekrkd0"></a></div>