<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="http://www.r-bloggers.com/on-whether-y-axis-labels-are-always-necessary/"></div></div><div><a data-url="http://www.r-bloggers.com/on-whether-y-axis-labels-are-always-necessary/" data-counturl="http://www.r-bloggers.com/on-whether-y-axis-labels-are-always-necessary/" data-count="horizontal" data-text="On Whether Y-axis Labels Are Always Necessary" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://rud.is/b/2016/06/12/on-whether-y-axis-labels-are-always-necessary/"> R – rud.is</a></strong>, and kindly contributed to <a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>The infamous <a target="_blank" href="http://twitter.com/albertocairo">@albertocairo</a> <a target="_blank" href="http://www.thefunctionalart.com/2016/06/propublica-visualizes-seasonality-in.html">blogged about</a> a <a target="_blank" href="https://projects.propublica.org/graphics/dividend">nice interactive piece on German company tax avoidance</a> by <a target="_blank" href="http://twitter.com/ProPublica">@ProPublica</a>. Here’s a snapshot of their interactive chart:</p>
<p><img alt="" src="https://2.bp.blogspot.com/-S-8bu1UdYWM/V1rXibnBxrI/AAAAAAAAGo0/L940SpU3DvUPX90JK82jrKQN6fWMyn2IACLcB/s1600/1prop.png"></p>
<p>Dr. Cairo (his PhD is in the bag as far as I’m concerned <img alt=":-)" class="wp-smiley" src="http://i2.wp.com/www.r-bloggers.com/wp-includes/images/smilies/simple-smile.png?w=456" data-recalc-dims="1"> posited:</p>
<blockquote>
<p><em>Isn’t it weird that the chart doesn’t have a scale on the Y-axis? It’s not the first time I see this, and it makes me feel uneasy.</em></p>
</blockquote>
<p>I jumped over to the interactive piece to see if the authors used interactive tooltips since viewers can get a good idea for the scale limits if they do that and it <em>kinda sorta</em> makes not having Y-axis label mostly OK if they compensate with said interactive notations. The interactive had no tooltips and the Y-axis was completely unlabeled.</p>
<p>Now, they used D3, so there <em>are</em> built-in ways to create and add a Y-axis, so I don’t think this was an “oops…we forgot” moment. The Y values are “Short Interest Quantity” which is the quantity of stock shares that investors have sold short but not yet covered or closed out. It’s definitely a “1%-er” term and the authors already took time to explain some technical financial details and probably would have had to add even more text to explain this term properly (since that short definition is really not enough for most of us 99%-ers). It seems that they felt the the arrowed-annotations on the right hand side of the plot made up for the lack of actual Y-axis detail.</p>
<p>Should we <em>always</em> have labels on a given axis? Would knowing that the Y-axis on this chart went from 0 to 800 million have aided in the decoding or groking the overall message? Here’s another example to help frame that question. This is the seminal <code>ggplot2::geom_density()</code> demo chart:</p>
<p><a target="_blank" href="https://rud.is/b/wp-content/uploads/2016/06/RStudio-2.png"><img alt="RStudio 2" width="75%" class="wp-image-4431" src="https://rud.is/b/wp-content/uploads/2016/06/RStudio-2.png"></a></p>
<p>Given that folks outside the realm of statistics/datasci really don’t grok what that Y-axis is saying, would it be <em>horribad</em> to just leave it with a <em>“density”</em> Y-label (sans unit marks) and then explain it in text (or talk to/around it in text but not go into detail)? Or should we keep the full annotations and spend a precious paragraph of text talking about measuring the area under a curve? (Another argument is to choose the right vis for the right audience but that’s another post entirely).</p>
<p>To further illustrate the posit, I recently made a series of what I call a “rank ordered segment plot” for a <a target="_blank" href="https://information.rapid7.com/rs/495-KNT-277/images/rapid7-research-report-national-exposure-index-060716.pdf">report</a> that we did at <a target="_blank" href="http://twitter.com/Rapid7">@Rapid7</a>:</p>
<p><a target="_blank" href="https://rud.is/b/wp-content/uploads/2016/06/ssh_rank_chart-1.png"><img height="1056" alt="ssh_rank_chart-1" width="1920" class="wp-image-4434" src="https://rud.is/b/wp-content/uploads/2016/06/ssh_rank_chart-1.png"></a></p>
<p>There are text annotations for countries at either end of the spectrum on the X-axis but they aren’t individually labeled cuz…ewwww that’d be messy. The interactive version (coming this week over at <code>community.rapid7.com</code>) has the full table and light hover popup-annotations. But the point wasn’t to really focus on the countries as it was to depict the sad state of the ratio of unencrypted vs encrypted for a given service type within a country.</p>
<p>So, <em>should</em> the ProPublica authors have tried to be more discrete w/r/t their Y-axis or is it fine the way it is? Does there <em>always</em> need to be discrete axes annotations or is there some wiggle room? Opines are welcome in the comments since I honestly don’t think there is “one answer to rule them all” for this.</p>
<p>And for those that really want to see more discrete info on the ProPublica Y-axis labels, here’s a static, faceted chart (you may need to click/select/tap the chart to make it big enough to view):</p>
<p><a target="_blank" href="https://rud.is/b/wp-content/uploads/2016/06/Plot_Zoom.png"><img height="1720" alt="Plot_Zoom" width="1992" class="wp-image-4438" src="https://rud.is/b/wp-content/uploads/2016/06/Plot_Zoom.png"></a></p>
<h3><strike>Don’t</strike>Try This At Home!</h3>
<p>ProPublica made that data available via two CSV files and the crosswalk org translation table via their main D3 javascript file (use Developer Tools “Inspect Element” to see such things). I ended up having to use <code>Sys.setlocale('LC_ALL','C')</code> and expand the translation table a bit due to some of the mixed encodings in the data sets. Code to make the chart is below.</p>
<pre><code>library(ggplot2)
library(dplyr)
library(stringi)
library(hrbrmisc)
library(scales)
library(ggalt)
library(sitools)

# mixed encodings ftw!
Sys.setlocale('LC_ALL','C') 

# different names in different data sets; sigh
org_crosswalk &lt;- read.table(text='company,trans
&quot;Adidas AG&quot;,&quot;Adidas AG&quot;
&quot;Allianz SE&quot;,&quot;Allianz SE&quot;
&quot;BASF SE&quot;,&quot;BASF SE&quot;
&quot;Bayer AG&quot;,&quot;Bayer AG&quot;
&quot;Bayerische Motoren Werke AG&quot;,&quot;BMW AG&quot;
&quot;BMW AG&quot;,&quot;BMW AG&quot;,
&quot;Beiersdorf AG&quot;,&quot;Beiersdorf AG&quot;
&quot;Commerzbank AG&quot;,&quot;Commerzbank AG&quot;
&quot;Continental AG&quot;,&quot;Continental AG&quot;
&quot;Daimler AG&quot;,&quot;Daimler AG&quot;
&quot;Deutsche Bank AG&quot;,&quot;Deutsche Bank AG&quot;
&quot;Deutsche Boerse AG&quot;,&quot;Deutsche Boerse AG&quot;
&quot;Deutsche Lufthansa AG&quot;,&quot;Deutsche Lufthansa AG&quot;
&quot;Deutsche Post AG&quot;,&quot;Deutsche Post AG&quot;
&quot;Deutsche Telekom AG&quot;,&quot;Deutsche Telekom AG&quot;
&quot;E.ON&quot;,&quot;E.ON&quot;
&quot;Fresenius Medical Care AG &amp; Co. KGaA&quot;,&quot;Fresenius Medical Care AG&quot;
&quot;Fresenius Medical Care AG&quot;,&quot;Fresenius Medical Care AG&quot;
&quot;Fresenius SE &amp; Co KGaA&quot;,&quot;Fresenius SE &amp; Co KGaA&quot;
&quot;HeidelbergCement AG&quot;,&quot;HeidelbergCement AG&quot;
&quot;Henkel AG &amp; Co. KGaA&quot;,&quot;Henkel AG &amp; Co. KGaA&quot;
&quot;Infineon Technologies AG&quot;,&quot;Infineon Technologies AG&quot;
&quot;K+S AG&quot;,&quot;K+S AG&quot;
&quot;Lanxess AG&quot;,&quot;Lanxess AG&quot;
&quot;Linde AG&quot;,&quot;Linde AG&quot;
&quot;Merck KGaA&quot;,&quot;Merck KGaA&quot;
&quot;MŸnchener RŸckversicherungs-Gesellschaft AG&quot;,&quot;Munich RE AG&quot;
&quot;M�nchener R�ckversicherungs-Gesellschaft AG&quot;,&quot;Munich RE AG&quot;
&quot;M\x9fnchener R\x9fckversicherungs-Gesellschaft AG&quot;,&quot;Munich RE AG&quot;
&quot;M?nchener R?ckversicherungs-Gesellschaft AG&quot;,&quot;Munich RE AG&quot;
&quot;Munich RE AG&quot;,&quot;Munich RE AG&quot;
&quot;RWE AG&quot;,&quot;RWE AG&quot;
&quot;SAP SE&quot;,&quot;SAP SE&quot;
&quot;Siemens AG&quot;,&quot;Siemens AG&quot;
&quot;ThyssenKrupp AG&quot;,&quot;ThyssenKrupp AG&quot;
&quot;Volkswagen AG&quot;,&quot;Volkswagen AG&quot;', stringsAsFactors=FALSE, sep=&quot;,&quot;, quote='&quot;', header=TRUE)

# quicker/less verbose than left_join()
org_trans &lt;- setNames(org_crosswalk$trans, org_crosswalk$company)

# get and clean both data sets, being kind to the propublica bandwidth $
rec_url &lt;- &quot;https://projects.propublica.org/graphics/javascripts/dividend/record_dates.csv&quot;
rec_fil &lt;- basename(rec_url)
if (!file.exists(rec_fil)) download.file(rec_url, rec_fil)

records &lt;- read.csv(rec_fil, stringsAsFactors=FALSE)
records %>%
  select(company=1, year=2, record_date=3) %>%
  mutate(record_date=as.Date(stri_replace_all_regex(record_date,
                                                    &quot;([[:digit:]]+)/([[:digit:]]+)+/([[:digit:]]+)$&quot;,
                                                    &quot;20$3-$1-$2&quot;))) %>%
  mutate(company=ifelse(grepl(&quot;Gesellschaft&quot;, company), &quot;Munich RE AG&quot;, company)) %>% 
  mutate(company=org_trans[company]) -> records

div_url &lt;- &quot;https://projects.propublica.org/graphics/javascripts/dividend/dividend.csv&quot;
div_fil &lt;- basename(div_url)
if (!file.exists(div_fil)) download.file(div_url, div_fil)

dividends &lt;- read.csv(div_fil, stringsAsFactors=FALSE)

dividends %>%
  select(company=1, pricing_date=2, short_int_qty=3) %>%
  mutate(pricing_date=as.Date(stri_replace_all_regex(pricing_date,
                                                     &quot;([[:digit:]]+)/([[:digit:]]+)+/([[:digit:]]+)$&quot;,
                                                     &quot;20$3-$1-$2&quot;))) %>%
  mutate(company=ifelse(grepl(&quot;Gesellschaft&quot;, company), &quot;Munich RE AG&quot;, company)) %>% 
  mutate(company=org_trans[company]) -> dividends

# sitools::f2si() doesn't work so well for this for some reason, so mk a small helper function
m_fmt &lt;- function (x) { sprintf(&quot;%d M&quot;, as.integer(x/1000000)) }

# gotta wrap'em all
subt &lt;- wrap_format(160)(&quot;German companies typically pay shareholders one big dividend a year. With the help of U.S. banks, international investors briefly lend their shares to German funds that don’t have to pay a dividend tax. The avoided tax – usually 15 percent of the dividend – is split by the investors and other participants in the deal. These transactions cost the German treasury about $1 billion a year. [Y-axis == short interest quantity]&quot;)

gg &lt;- ggplot()

# draw the markers for the dividends
gg &lt;- gg + geom_vline(data=records,
                      aes(xintercept=as.numeric(record_date)),
                      color=&quot;#b2182b&quot;, size=0.25, linetype=&quot;dotted&quot;)

# draw the time series
gg &lt;- gg + geom_line(data=dividends,
                     aes(pricing_date, short_int_qty, group=company),
                     size=0.15)

gg &lt;- gg + scale_x_date(expand=c(0,0))
gg &lt;- gg + scale_y_continuous(expand=c(0,0), labels=m_fmt,
                              limits=c(0,800000000))

gg &lt;- gg + facet_wrap(~company, scales=&quot;free_x&quot;)

gg &lt;- gg + labs(x=&quot;Red, dotted line == Dividend date&quot;, y=NULL,
                title=&quot;Tax Avoidance Has a Heartbeat&quot;,
                subtitle=subt,
                caption=&quot;Source: https://projects.propublica.org/graphics/dividend&quot;)

# devtools::install_github(&quot;hrbrmstr/hrbrmisc&quot;) or roll your own
gg &lt;- gg + theme_hrbrmstr_an(grid=&quot;XY&quot;, axis=&quot;&quot;, strip_text_size=8.5,
                             subtitle_size=10)
gg &lt;- gg + theme(axis.text=element_text(size=6))
gg &lt;- gg + theme(panel.grid.major=element_line(size=0.05))
gg &lt;- gg + theme(panel.background=element_rect(fill=&quot;#e2e2e233&quot;,
                                               color=&quot;#e2e2e233&quot;))
gg &lt;- gg + theme(panel.margin=margin(10,10,20,10))
gg &lt;- gg + theme(plot.margin=margin(20,20,20,20))
gg &lt;- gg + theme(axis.title.x=element_text(color=&quot;#b2182bee&quot;, size=9, hjust=1))
gg &lt;- gg + theme(plot.caption=element_text(margin=margin(t=5)))
gg</code></pre>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="http://www.r-bloggers.com/on-whether-y-axis-labels-are-always-necessary/"></div></div><div><a data-url="http://www.r-bloggers.com/on-whether-y-axis-labels-are-always-necessary/" data-counturl="http://www.r-bloggers.com/on-whether-y-axis-labels-are-always-necessary/" data-count="vertical" data-text="On Whether Y-axis Labels Are Always Necessary" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://rud.is/b/2016/06/12/on-whether-y-axis-labels-are-always-necessary/"> R – rud.is</a></strong>.</div>
<hr>
<a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="http://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="http://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="http://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="http://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="http://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="http://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="http://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="http://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="http://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="http://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="http://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="http://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="http://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="http://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="http://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="http://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/HX4HTvE6O50"></a></div>