<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/years-as-coloured-bars/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://nsaunders.wordpress.com/2017/08/05/years-as-coloured-bars/"> 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><a rel="nofollow" href="https://nsaunders.wordpress.com/2017/08/05/years-as-coloured-bars/barchart4/" target="_blank"><img data-orig-file="https://nsaunders.files.wordpress.com/2017/08/barchart4.png" data-orig-size="500,400" data-medium-file="https://nsaunders.files.wordpress.com/2017/08/barchart4.png?w=300&amp;h=240&amp;fit=300%2C240&amp;resize=300%2C240" data-attachment-id="4909" data-image-meta="{" data-image-description="" src="https://nsaunders.files.wordpress.com/2017/08/barchart4.png?w=300&h=240&fit=300%2C240&resize=300%2C240" data-permalink="https://nsaunders.wordpress.com/2017/08/05/years-as-coloured-bars/barchart4/" data-large-file="https://nsaunders.files.wordpress.com/2017/08/barchart4.png?w=500" alt="" data-image-title="barchart4" sizes="(max-width: 300px) 100vw, 300px" data-comments-opened="1" class="wp-image-4909" data-recalc-dims="1"></a>I keep seeing years represented by coloured bars. First it was that <a rel="nofollow" href="https://nsaunders.wordpress.com/2017/07/21/chart-golf-the-demographic-tsunami/" target="_blank">demographic tsunami chart</a>. Then there are examples like the one on the right, which came up in a web search today. I even saw one (whispers) at work today.</p>
<p>I get what they are trying to do – illustrate trends within categories over time – but I don’t think years as coloured bars is the way to go. To me, progression over time suggests that time should be an axis, so as the eye moves along the data from one end to the other, without interruption. What I want to see is categories over time, not time within categories.</p>
<p>So what is the way to go? Let’s ask “what would ggplot2 do?”<br>
<span></span><br>
The following charts illustrate different ways to visualise the same data using <code>ggplot2</code>. My motivation here is to show you that if you don’t immediately know or see a “right way” to do something, tools such as <code>ggplot2</code> make it easy to “feel your way” to a solution, through exploration.</p>
<p>The charts and their accompanying code are <a rel="nofollow" href="http://rpubs.com/neilfws/296600" target="_blank">available at RPubs</a>. Click each image at right for a full-size version.</p>
<p><a rel="nofollow" href="https://nsaunders.wordpress.com/2017/08/05/years-as-coloured-bars/bars-year-1/" target="_blank"><img data-orig-file="https://nsaunders.files.wordpress.com/2017/08/bars-year-1.png" data-orig-size="1344,960" data-medium-file="https://nsaunders.files.wordpress.com/2017/08/bars-year-1.png?w=300&amp;h=214&amp;fit=300%2C214&amp;resize=300%2C214" data-attachment-id="4913" data-image-meta="{" data-image-description="" src="https://nsaunders.files.wordpress.com/2017/08/bars-year-1.png?w=300&h=214&fit=300%2C214&resize=300%2C214" data-permalink="https://nsaunders.wordpress.com/2017/08/05/years-as-coloured-bars/bars-year-1/" data-large-file="https://nsaunders.files.wordpress.com/2017/08/bars-year-1.png?w=1024" alt="" data-image-title="bars-year-1" sizes="(max-width: 300px) 100vw, 300px" data-comments-opened="1" class="wp-image-4913" data-recalc-dims="1"></a>To start, we can create our own “years as coloured bars” chart, using some toy data.</p>
<p>It looks better already just for being generated using <code>ggplot2</code>. But can we go better?</p>
<p><br></p>
<p><a rel="nofollow" href="https://nsaunders.wordpress.com/2017/08/05/years-as-coloured-bars/bars-category-1/" target="_blank"><img data-orig-file="https://nsaunders.files.wordpress.com/2017/08/bars-category-1.png" data-orig-size="1344,960" data-medium-file="https://nsaunders.files.wordpress.com/2017/08/bars-category-1.png?w=300&amp;h=214&amp;fit=300%2C214&amp;resize=300%2C214" data-attachment-id="4921" data-image-meta="{" data-image-description="" src="https://nsaunders.files.wordpress.com/2017/08/bars-category-1.png?w=300&h=214&fit=300%2C214&resize=300%2C214" data-permalink="https://nsaunders.wordpress.com/2017/08/05/years-as-coloured-bars/bars-category-1/" data-large-file="https://nsaunders.files.wordpress.com/2017/08/bars-category-1.png?w=1024" alt="" data-image-title="bars-category-1" sizes="(max-width: 300px) 100vw, 300px" data-comments-opened="1" class="wp-image-4921" data-recalc-dims="1"></a>Your first thought might be “why not just swap the years and categories around?” And sure, that gives us time along an axis. Now though, it’s a little difficult to follow each category, as the eye has to skip all the others when moving to the next time point.</p>
<p><br></p>
<p><a rel="nofollow" href="https://nsaunders.wordpress.com/2017/08/05/years-as-coloured-bars/bars-category-stacked-1/" target="_blank"><img data-orig-file="https://nsaunders.files.wordpress.com/2017/08/bars-category-stacked-1.png" data-orig-size="1344,960" data-medium-file="https://nsaunders.files.wordpress.com/2017/08/bars-category-stacked-1.png?w=300&amp;h=214&amp;fit=300%2C214&amp;resize=300%2C214" data-attachment-id="4923" data-image-meta="{" data-image-description="" src="https://nsaunders.files.wordpress.com/2017/08/bars-category-stacked-1.png?w=300&h=214&fit=300%2C214&resize=300%2C214" data-permalink="https://nsaunders.wordpress.com/2017/08/05/years-as-coloured-bars/bars-category-stacked-1/" data-large-file="https://nsaunders.files.wordpress.com/2017/08/bars-category-stacked-1.png?w=1024" alt="" data-image-title="bars-category-stacked-1" sizes="(max-width: 300px) 100vw, 300px" data-comments-opened="1" class="wp-image-4923" data-recalc-dims="1"></a>OK you say, I can get all the categories at the same time point by stacking. A couple of problems now: first, abrupt changes in value can make a category shrink dramatically or move around vertically in a distracting fashion. And second, making the categories proportional can make it difficult to determine the absolute values for anything other than the lowest row of the bars.</p>
<p><br></p>
<p><a rel="nofollow" href="https://nsaunders.wordpress.com/2017/08/05/years-as-coloured-bars/bars-category-filled-1/" target="_blank"><img data-orig-file="https://nsaunders.files.wordpress.com/2017/08/bars-category-filled-1.png" data-orig-size="1344,960" data-medium-file="https://nsaunders.files.wordpress.com/2017/08/bars-category-filled-1.png?w=300&amp;h=214&amp;fit=300%2C214&amp;resize=300%2C214" data-attachment-id="4924" data-image-meta="{" data-image-description="" src="https://nsaunders.files.wordpress.com/2017/08/bars-category-filled-1.png?w=300&h=214&fit=300%2C214&resize=300%2C214" data-permalink="https://nsaunders.wordpress.com/2017/08/05/years-as-coloured-bars/bars-category-filled-1/" data-large-file="https://nsaunders.files.wordpress.com/2017/08/bars-category-filled-1.png?w=1024" alt="" data-image-title="bars-category-filled-1" sizes="(max-width: 300px) 100vw, 300px" data-comments-opened="1" class="wp-image-4924" data-recalc-dims="1"></a>What if we stack and fill so all the bars add up to 100%? Better, but still has some of the issues with the previous plot.</p>
<p><br></p>
<p><a rel="nofollow" href="https://nsaunders.wordpress.com/2017/08/05/years-as-coloured-bars/area-category-filled-1/" target="_blank"><img data-orig-file="https://nsaunders.files.wordpress.com/2017/08/area-category-filled-1.png" data-orig-size="1344,960" data-medium-file="https://nsaunders.files.wordpress.com/2017/08/area-category-filled-1.png?w=300&amp;h=214&amp;fit=300%2C214&amp;resize=300%2C214" data-attachment-id="4925" data-image-meta="{" data-image-description="" src="https://nsaunders.files.wordpress.com/2017/08/area-category-filled-1.png?w=300&h=214&fit=300%2C214&resize=300%2C214" data-permalink="https://nsaunders.wordpress.com/2017/08/05/years-as-coloured-bars/area-category-filled-1/" data-large-file="https://nsaunders.files.wordpress.com/2017/08/area-category-filled-1.png?w=1024" alt="" data-image-title="area-category-filled-1" sizes="(max-width: 300px) 100vw, 300px" data-comments-opened="1" class="wp-image-4925" data-recalc-dims="1"></a>How about filling, but using an area plot instead of bars?</p>
<p>I think this works much better: the continuous connection of categories makes it easier to follow each one through time. However, there is still the issue of relative versus absolute values. And to my eye, downward lines can be interpreted as decreases even when the width of the area for a category indicates that the value has increased.</p>
<p><br></p>
<p><a rel="nofollow" href="https://nsaunders.wordpress.com/2017/08/05/years-as-coloured-bars/lines-category-1/" target="_blank"><img data-orig-file="https://nsaunders.files.wordpress.com/2017/08/lines-category-1.png" data-orig-size="1344,960" data-medium-file="https://nsaunders.files.wordpress.com/2017/08/lines-category-1.png?w=300&amp;h=214&amp;fit=300%2C214&amp;resize=300%2C214" data-attachment-id="4926" data-image-meta="{" data-image-description="" src="https://nsaunders.files.wordpress.com/2017/08/lines-category-1.png?w=300&h=214&fit=300%2C214&resize=300%2C214" data-permalink="https://nsaunders.wordpress.com/2017/08/05/years-as-coloured-bars/lines-category-1/" data-large-file="https://nsaunders.files.wordpress.com/2017/08/lines-category-1.png?w=1024" alt="" data-image-title="lines-category-1" sizes="(max-width: 300px) 100vw, 300px" data-comments-opened="1" class="wp-image-4926" data-recalc-dims="1"></a>Coloured lines? They can work – in parallel coordinates for example – but in this case, the overlaps make a mess.</p>
<p><br></p>
<p><a rel="nofollow" href="https://nsaunders.wordpress.com/2017/08/05/years-as-coloured-bars/lines-category-facet-1/" target="_blank"><img data-orig-file="https://nsaunders.files.wordpress.com/2017/08/lines-category-facet-1.png" data-orig-size="1344,960" data-medium-file="https://nsaunders.files.wordpress.com/2017/08/lines-category-facet-1.png?w=300&amp;h=214&amp;fit=300%2C214&amp;resize=300%2C214" data-attachment-id="4927" data-image-meta="{" data-image-description="" src="https://nsaunders.files.wordpress.com/2017/08/lines-category-facet-1.png?w=300&h=214&fit=300%2C214&resize=300%2C214" data-permalink="https://nsaunders.wordpress.com/2017/08/05/years-as-coloured-bars/lines-category-facet-1/" data-large-file="https://nsaunders.files.wordpress.com/2017/08/lines-category-facet-1.png?w=1024" alt="" data-image-title="lines-category-facet-1" sizes="(max-width: 300px) 100vw, 300px" data-comments-opened="1" class="wp-image-4927" data-recalc-dims="1"></a>Let’s start thinking about facets: separate regions within the chart for each category. First attempt.</p>
<p>Now we’re getting somewhere – much easier to follow each category over time. One issue with this particular arrangement is that it’s a little difficult to compare categories and the eye finds it difficult to isolate a facet from surrounding facets.</p>
<p><br></p>
<p><a rel="nofollow" href="https://nsaunders.wordpress.com/2017/08/05/years-as-coloured-bars/bars-year-facet-1/" target="_blank"><img data-orig-file="https://nsaunders.files.wordpress.com/2017/08/bars-year-facet-1.png" data-orig-size="1344,960" data-medium-file="https://nsaunders.files.wordpress.com/2017/08/bars-year-facet-1.png?w=300&amp;h=214&amp;fit=300%2C214&amp;resize=300%2C214" data-attachment-id="4928" data-image-meta="{" data-image-description="" src="https://nsaunders.files.wordpress.com/2017/08/bars-year-facet-1.png?w=300&h=214&fit=300%2C214&resize=300%2C214" data-permalink="https://nsaunders.wordpress.com/2017/08/05/years-as-coloured-bars/bars-year-facet-1/" data-large-file="https://nsaunders.files.wordpress.com/2017/08/bars-year-facet-1.png?w=1024" alt="" data-image-title="bars-year-facet-1" sizes="(max-width: 300px) 100vw, 300px" data-comments-opened="1" class="wp-image-4928" data-recalc-dims="1"></a>How about wrapping facets, instead of a grid? Let’s try first with facets by year and bars for categories.</p>
<p>Not bad at all – this makes categories within a year very clear. But wait, we wanted a good view of each category over time. So how about…</p>
<p><br></p>
<p><a rel="nofollow" href="https://nsaunders.wordpress.com/2017/08/05/years-as-coloured-bars/lines-year-facet-1/" target="_blank"><img data-orig-file="https://nsaunders.files.wordpress.com/2017/08/lines-year-facet-1.png" data-orig-size="1344,960" data-medium-file="https://nsaunders.files.wordpress.com/2017/08/lines-year-facet-1.png?w=300&amp;h=214&amp;fit=300%2C214&amp;resize=300%2C214" data-attachment-id="4929" data-image-meta="{" data-image-description="" src="https://nsaunders.files.wordpress.com/2017/08/lines-year-facet-1.png?w=300&h=214&fit=300%2C214&resize=300%2C214" data-permalink="https://nsaunders.wordpress.com/2017/08/05/years-as-coloured-bars/lines-year-facet-1/" data-large-file="https://nsaunders.files.wordpress.com/2017/08/lines-year-facet-1.png?w=1024" alt="" data-image-title="lines-year-facet-1" sizes="(max-width: 300px) 100vw, 300px" data-comments-opened="1" class="wp-image-4929" data-recalc-dims="1"></a>…facet by category using lines for years.</p>
<p>I think we have a winner. This clearly illustrates change per category over time and the layout and common scales even allow for comparison between categories.</p>
<p><br></p>
<p>We started out complaining about time within categories but in fact, that is what we wanted after all: just arranged in a better way than years as coloured bars .</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/ggplot2/" target="_blank">ggplot2</a>, <a rel="nofollow" href="https://nsaunders.wordpress.com/tag/visualisation/" target="_blank">visualisation</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nsaunders.wordpress.com/4908/" target="_blank"><img border="0" alt="" src="http://feeds.wordpress.com/1.0/comments/nsaunders.wordpress.com/4908/"></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/08/05/years-as-coloured-bars/"> 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/4kHAbddsmWw" height="1"></a></div>