<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/five-problems-and-one-solution-with-dual-axis-time-series-plots/"></div></div><div><a data-url="https://www.r-bloggers.com/five-problems-and-one-solution-with-dual-axis-time-series-plots/" data-counturl="https://www.r-bloggers.com/five-problems-and-one-solution-with-dual-axis-time-series-plots/" data-count="horizontal" data-text="Five problems (and one solution) with dual-axis time series plots" 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://blog.revolutionanalytics.com/2016/08/dual-axis-time-series.html"> Revolutions</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<div>
<p>If you need to present two time series spanning the same period, but in wildly different scales, it's tempting to use a time series chart with two separate vertical axes, one for each series, like this one <a target="_blank" href="http://www.rbnz.govt.nz/statistics/key-graphs/key-graph-exchange-rate">from the Reserve Bank of New Zealand</a>:</p>
<p><a target="_blank" href="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01b8d21244c9970c-pi"><img title="Nzusdexchange" alt="Nzusdexchange" src="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01b8d21244c9970c-800wi" border="0"></a></p>
<p>Charts like this typically have one or more crossover points, and that crossing imparts meaning to the viewer of the sense that one series is now &quot;ahead&quot; of the other. One problem is that <strong>crossover-points in dual-axis time series charts are entirely arbitrary</strong>. Changing either the left-hand or right-hand scale (and replotting the data accordingly) will change where the crossover points appear. And (as if often the case) the scales are automatically chosen to allow each series to use the full vertical space available, just changing the time-range of the data plotted will also change the location of the crossover points.</p>
<p>In an excellent blog post, statistician Peter Ellis points out <a target="_blank" href="http://ellisp.github.io/blog/2016/08/18/dualaxes">five problems with dual-axis time series charts</a>:</p>
<ol>
<li>The designer has to make choices about scales and this can have a big impact on the viewer</li>
<li>In particular, “cross-over points” where one series cross another are results of the design choices, not intrinsic to the data, and viewers (particularly unsophisticated viewers) will not appreciate this and think there is more significance in cross over than is actually the case</li>
<li>They make it easier to lazily associate correlation with causation, not taking into account autocorrelation and other time-series issues</li>
<li>Because of the issues above, in malicious hands they make it possible to deliberately mislead</li>
<li>They often look cluttered and aesthetically unpleasing</li>
</ol>
<p>A simple alternative is to rescale both time series, for example to define both series to have a nominal value at a specific time, say both start at 100 on January 1, 2016. This is a useful way to compare the growth in two series since the beginning of the year, and means that both can be represented using the same single scale. (If you're using the ggplot2 package in R to plot time series, you can use the <a target="_blank" href="http://www.rdocumentation.org/packages/ggseas/versions/0.4.0/topics/stat_index">stat_index</a> function from Peter's <a target="_blank" href="https://mran.microsoft.com/package/ggseas/">ggseas package</a> to scale time series in this way.) The problem though is that you use the interpretability of the chart, having now lost the true scales for <em>both</em> time series.</p>
<p>All that being said, Peter suggests that there are times when a dual-axis chart can be appropriate, for example when the two axes are conceptually similar (as above, when both are linear monetary scales), and you use a consistent process to set the scales of the vertical axes. Other considerations include color-coding the axes for interpretability, and choosing colors that don't favor one series over the other. Implementing these best practices, Peter has created the <span><a target="_blank" href="https://gist.github.com/ellisp/4002241def4e2b360189e58c3f461b4a#file-dualplot-r">dualplot()</a></span> function for R, which cooses the axes according to a cross-over point you specify. This is equivalent to rescaling the series to have the same value at that specified points, but keeps the real-value axes for interpretability. Heres' the above chart, rendered with <span>dualplot()</span> with a crossover point at January 2104:</p>
<p><a target="_blank" href="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01b8d2129ecc970c-pi"><img title="Dualplot" alt="Dualplot" src="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01b8d2129ecc970c-800wi" border="0"></a></p>
<p>For more great discussion of the pros and cons of dual-axis time series charts, and the R code for the <span>dualplot()</span> function, follow the link to Peter's blog post below.</p>
<p>Peter's stats stuff: <a target="_blank" href="http://ellisp.github.io/blog/2016/08/18/dualaxes">Dual axes time series plots may be ok sometimes after all</a> (<a target="_blank" href="https://twitter.com/HarlanH/status/766266153811542018">via</a> Harlan Harris)</p>
</div>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="https://www.r-bloggers.com/five-problems-and-one-solution-with-dual-axis-time-series-plots/"></div></div><div><a data-url="https://www.r-bloggers.com/five-problems-and-one-solution-with-dual-axis-time-series-plots/" data-counturl="https://www.r-bloggers.com/five-problems-and-one-solution-with-dual-axis-time-series-plots/" data-count="vertical" data-text="Five problems (and one solution) with dual-axis time series plots" 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://blog.revolutionanalytics.com/2016/08/dual-axis-time-series.html"> Revolutions</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/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/?s=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/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/dYkUqnV5z3Y"></a></div>