<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/chart-golf-the-demographic-tsunami/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://nsaunders.wordpress.com/2017/07/21/chart-golf-the-demographic-tsunami/"> 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>“‘Demographic tsunami’ will keep Sydney, Melbourne property prices high” <a rel="nofollow" href="http://www.smh.com.au/business/the-economy/demographic-tsunami-will-keep-sydney-melbourne-property-prices-high-20170629-gx1onj.html" target="_blank">screams the headline</a>.</p>
<p><a rel="nofollow" href="https://nsaunders.wordpress.com/smh-tsunami/" target="_blank"><img data-orig-file="https://nsaunders.files.wordpress.com/2017/07/smh-tsunami.jpg" data-orig-size="1411,835" data-medium-file="https://nsaunders.files.wordpress.com/2017/07/smh-tsunami.jpg?w=300&amp;h=178&amp;fit=300%2C178&amp;resize=300%2C178" data-attachment-id="4810" data-image-meta="{" data-image-description="" src="https://nsaunders.files.wordpress.com/2017/07/smh-tsunami.jpg?w=300&h=178&fit=300%2C178&resize=300%2C178" data-permalink="https://nsaunders.wordpress.com/2017/07/21/chart-golf-the-demographic-tsunami/smh-tsunami/" data-large-file="https://nsaunders.files.wordpress.com/2017/07/smh-tsunami.jpg?w=1024" alt="" data-image-title="smh-tsunami" sizes="(max-width: 300px) 100vw, 300px" data-comments-opened="1" class="wp-image-4810" data-recalc-dims="1"></a></p>
<blockquote><p>While the census showed Australia overall is aging, there’s been a noticeable lift in the number of people aged between 25 to 32.<br>
As the accompanying graph shows…</p>
</blockquote>
<p>Whoa, that is one ugly chart. First thought: let’s not be too hard on Fairfax Media, they’ve sacked most of their real journalists and they took the chart from <a rel="nofollow" href="http://petewargent.blogspot.com.au/2017/06/demographic-tsunami.html" target="_blank">someone else</a>. Second thought: if you want to visualise change over time, time as an axis rather than a coloured bar is generally a good idea.</p>
<p>Can we do better?<br>
<span></span></p>
<p>As usual, you can find <a rel="nofollow" href="https://github.com/neilfws/ABSData/tree/master/population" target="_blank">this project at Github</a>, with an accompanying <a rel="nofollow" href="http://rpubs.com/neilfws/292731" target="_blank">published document at RPubs</a>. I rarely copy/paste/format code here any more so if you want the details, take a look at <a rel="nofollow" href="https://github.com/neilfws/ABSData/blob/master/population/code/R/tsunami.Rmd" target="_blank">the Rmd file</a>. Some of the charts in this post are thumbnails, so click on them for the full-sized version. </p>
<p>First, grab the raw data: in this case, <a rel="nofollow" href="http://www.abs.gov.au/AUSSTATS/abs@.nsf/DetailsPage/3101.0Dec%202016?OpenDocument" target="_blank">a spreadsheet</a> (Table 59) from the Australian Bureau of Statistics (ABS). It contains counts of males, females and persons from ages 0 – 100+ in one year increments, for the years 1971 – 2016.</p>
<p>For some reason, government departments like to make their data as wide as possible. In this case, 251 columns where 1 = the year, 2 – 102 are male ages, 103-202 female ages and 203 – 251 are persons (male + female) ages 0 – 47. Persons ages 48 – 100+ are in a second sheet in the same file. No, I don’t know why either.</p>
<p>Fortunately, <em>readxl</em> takes care of all this, so all we need to do is give the columns some sensible names followed by the tidyr treatment.</p>
<p><code><br>
## # A tibble: 11,500 x 5<br>
##          Date gender   age  value  Year<br>
##<br>
##  1 1971-06-01      M     0 133347  1971<br>
##  2 1972-06-01      M     0 136987  1972<br>
##  3 1973-06-01      M     0 129492  1973<br>
##  4 1974-06-01      M     0 124803  1974<br>
##  5 1975-06-01      M     0 120678  1975<br>
##  6 1976-06-01      M     0 115457  1976<br>
##  7 1977-06-01      M     0 115298  1977<br>
##  8 1978-06-01      M     0 115249  1978<br>
##  9 1979-06-01      M     0 113443  1979<br>
## 10 1980-06-01      M     0 114488  1980<br>
## # ... with 11,490 more rows<br>
</code></p>
<p><strong>Ages 21-42 from 2005 – 2016</strong></p>
<p>The original chart from the SMH focused on ages 21 – 42 and years 2005 – 2016, so we’ll do the same. I thought it would be interesting to animate the changes in population by year. My first attempt posted to Twitter was incorrect, in that the numbers were summed year on year, so here’s a better version. The cumulative colouring gets a bit weird when numbers decrease, but I think it works to some degree.</p>
<p><a rel="nofollow" href="https://nsaunders.wordpress.com/2017/07/21/chart-golf-the-demographic-tsunami/tsunami-2/" target="_blank"><img data-orig-file="https://nsaunders.files.wordpress.com/2017/07/tsunami1.gif?w=456" data-orig-size="500,500" data-medium-file="https://nsaunders.files.wordpress.com/2017/07/tsunami1.gif?w=456?w=300" data-attachment-id="4822" data-image-meta="{" data-image-description="" src="https://nsaunders.files.wordpress.com/2017/07/tsunami1.gif?w=456" data-permalink="https://nsaunders.wordpress.com/2017/07/21/chart-golf-the-demographic-tsunami/tsunami-2/" data-large-file="https://nsaunders.files.wordpress.com/2017/07/tsunami1.gif?w=456?w=500" alt="" data-image-title="tsunami" data-comments-opened="1" class="wp-image-4822" data-recalc-dims="1"></a></p>
<p>Indeed, there does seem to be a recent surge in the “25 – 32 bracket” if that’s what we’re calling it.</p>
<p><strong>Ages 25-32 as a proportion of 21-42</strong><br>
<a rel="nofollow" href="https://nsaunders.wordpress.com/2017/07/21/chart-golf-the-demographic-tsunami/plot-25-32-fraction-1/" target="_blank"><img data-orig-file="https://nsaunders.files.wordpress.com/2017/07/plot-25-32-fraction-1.png" data-orig-size="672,480" data-medium-file="https://nsaunders.files.wordpress.com/2017/07/plot-25-32-fraction-1.png?w=300&amp;h=214&amp;fit=300%2C214&amp;resize=300%2C214" data-attachment-id="4819" data-image-meta="{" data-image-description="" src="https://nsaunders.files.wordpress.com/2017/07/plot-25-32-fraction-1.png?w=300&h=214&fit=300%2C214&resize=300%2C214" data-permalink="https://nsaunders.wordpress.com/2017/07/21/chart-golf-the-demographic-tsunami/plot-25-32-fraction-1/" data-large-file="https://nsaunders.files.wordpress.com/2017/07/plot-25-32-fraction-1.png?w=672" alt="" data-image-title="plot-25-32-fraction-1" sizes="(max-width: 300px) 100vw, 300px" data-comments-opened="1" class="wp-image-4819" data-recalc-dims="1"></a>Things get less tsunami-like when we try to visualize age brackets as a proportion of all ages. The 25-32 band grows a little but – tsunami?</p>
<p><strong>Ages 25-32 as a proportion of total</strong></p>
<p>When you put things out on Twitter, be sure that chart nerds will descent to join in the fun.</p>
<div>
<blockquote data-width="450" class="twitter-tweet">
<p dir="ltr" lang="en"><a rel="nofollow" href="https://twitter.com/PeteWargent" target="_blank">@PeteWargent</a> <a rel="nofollow" href="https://twitter.com/MichaelPascoe01" target="_blank">@MichaelPascoe01</a> If we're mainly interested in the &quot;prime house-buying population&quot; (25-32), I'd prob visualise it like this <a rel="nofollow" href="https://t.co/K4qqoL60tQ" target="_blank">pic.twitter.com/K4qqoL60tQ</a></p>
<p>— Matt Cowgill (@MattCowgill) <a rel="nofollow" href="https://twitter.com/MattCowgill/status/881800327560708097" target="_blank">July 3, 2017</a></p>
</blockquote>
<p></div>
<p><a rel="nofollow" href="https://nsaunders.wordpress.com/2017/07/21/chart-golf-the-demographic-tsunami/plot-25-32-cowgill-1/" target="_blank"><img data-orig-file="https://nsaunders.files.wordpress.com/2017/07/plot-25-32-cowgill-1.png" data-orig-size="768,480" data-medium-file="https://nsaunders.files.wordpress.com/2017/07/plot-25-32-cowgill-1.png?w=300&amp;h=188&amp;fit=300%2C188&amp;resize=300%2C188" data-attachment-id="4820" data-image-meta="{" data-image-description="" src="https://nsaunders.files.wordpress.com/2017/07/plot-25-32-cowgill-1.png?w=300&h=188&fit=300%2C188&resize=300%2C188" data-permalink="https://nsaunders.wordpress.com/2017/07/21/chart-golf-the-demographic-tsunami/plot-25-32-cowgill-1/" data-large-file="https://nsaunders.files.wordpress.com/2017/07/plot-25-32-cowgill-1.png?w=768" alt="" data-image-title="plot-25-32-cowgill-1" sizes="(max-width: 300px) 100vw, 300px" data-comments-opened="1" class="wp-image-4820" data-recalc-dims="1"></a>Matt rightly asks: what’s the proportion of 25-32 year-olds anyway? We can reproduce his line charts like so. Now we see that 25-32 year-olds as a percentage of total population have increased recently after an all-time (since 1971) low and in fact, the rate of increase seems to have slowed.</p>
<p>In conclusion then:</p>
<ul>
<li>Years as coloured bars: not great</li>
<li>Excel: no</li>
<li>“Tsunami”: hardly</li>
</ul>
<p><strong>Bonus section: population pyramids</strong><br>
I’ve always liked <a rel="nofollow" href="https://en.wikipedia.org/wiki/Population_pyramid" target="_blank">population pyramids</a>, ever since I first learned about them in high school geography class. Here’s my attempt to animate one. The trick is to subset the data by gender, then create two geoms and set the values for one subset to be negative (but not the labels). More commonly, ages are binned and proportions rather than counts may be used, but I did neither in this case.</p>
<p>I find it either mesmerising or a bit “too much”, depending on my mood. How about you?</p>
<p><a rel="nofollow" href="https://nsaunders.wordpress.com/2017/07/21/chart-golf-the-demographic-tsunami/pyramid/" target="_blank"><img data-orig-file="https://nsaunders.files.wordpress.com/2017/07/pyramid.gif?w=456" data-orig-size="500,500" data-medium-file="https://nsaunders.files.wordpress.com/2017/07/pyramid.gif?w=456?w=300" data-attachment-id="4824" data-image-meta="{" data-image-description="" src="https://nsaunders.files.wordpress.com/2017/07/pyramid.gif?w=456" data-permalink="https://nsaunders.wordpress.com/2017/07/21/chart-golf-the-demographic-tsunami/pyramid/" data-large-file="https://nsaunders.files.wordpress.com/2017/07/pyramid.gif?w=456?w=500" alt="" data-image-title="pyramid" data-comments-opened="1" class="wp-image-4824" data-recalc-dims="1"></a></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/news/" target="_blank">news</a>, <a rel="nofollow" href="https://nsaunders.wordpress.com/tag/smh/" target="_blank">smh</a>, <a rel="nofollow" href="https://nsaunders.wordpress.com/tag/sydney/" target="_blank">sydney</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/4803/" target="_blank"><img border="0" alt="" src="http://feeds.wordpress.com/1.0/comments/nsaunders.wordpress.com/4803/"></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/07/21/chart-golf-the-demographic-tsunami/"> 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/3VNPuSx5Gkg" height="1"></a></div>