<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/2016-australian-federal-election-flexdashboard/"></div></div><div><a data-url="https://www.r-bloggers.com/2016-australian-federal-election-flexdashboard/" data-counturl="https://www.r-bloggers.com/2016-australian-federal-election-flexdashboard/" data-count="horizontal" data-text="2016 Australian Federal Election Flexdashboard" 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://jcarroll.com.au/2016/08/01/auelection2016/"> R – Irregularly Scheduled Programming</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Here in the land down under we’ve finally completed our Federal election. We complain that it seems to go on for too long, but it’s a brief distraction compared to the USA electoral process. I managed to do a small analysis on the votes at a finer scale than I thought would be available, and created <a target="_blank" href="https://jcarroll.shinyapps.io/AUelection2016/">a flexdashboard to present the results</a>. Given that I couldn’t make it to <a target="_blank" href="http://www.govhack.org/">GovHack</a> this year, this open-data analysis sort of makes up for it.</p>
<p><span></span></p>
<p><a target="_blank" href="http://i1.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/voting.jpg"><img sizes="(max-width: 624px) 100vw, 624px" srcset="http://i1.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/voting.jpg?w=624 624w, http://i1.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/voting.jpg?resize=300%2C169 300w" alt="voting" class="wp-image-970" src="http://i1.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/voting.jpg?resize=624%2C351" data-recalc-dims="1"></a></p>
<p>This year turned out to be quite eventful (when aren’t they these days?) with what might appear to an outside observer to be a conspired attempt at a perfect split vote (a hung parliament). </p>
<p><a target="_blank" href="http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/08/elecSplit.png"><img sizes="(max-width: 502px) 100vw, 502px" srcset="http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/08/elecSplit.png?w=502 502w, http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/08/elecSplit.png?resize=259%2C300 259w, http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/08/elecSplit.png?resize=194%2C225 194w" alt="elecSplit" class="wp-image-989" src="http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/08/elecSplit.png?resize=502%2C582" data-recalc-dims="1"></a></p>
<p>In the end, it seems the incumbent Liberal/National Coalition managed to form government in their own right by the slimmest of margins, with one electorate triggering a recount when the margin dropped to a single vote. The final split ended up being <a target="_blank" href="http://www.abc.net.au/news/2016-07-31/election-2016-labor-wins-herbert-after-recount/7675898">a mere 37 votes</a>.</p>
<p>Things run a little more smoothly here because we (functionally) follow the <a target="_blank" href="https://en.wikipedia.org/wiki/Westminster_system">Westminster system</a> for electing a party rather than a specific leader, a fact that has resulted in our having 5 Prime Ministers (4 unique) in the last 6 years, despite elections being held every 4 years. </p>
<p><a target="_blank" href="http://i1.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/elec8.png"><img sizes="(max-width: 573px) 100vw, 573px" srcset="http://i1.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/elec8.png?w=573 573w, http://i1.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/elec8.png?resize=300%2C115 300w" alt="elec8" class="wp-image-979" src="http://i1.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/elec8.png?resize=573%2C220" data-recalc-dims="1"></a></p>
<p>Structurally, we are similar to the United States Congress in that we have a House of Representatives elected from single-member constituencies of approximately equal population, and a Senate consisting of an equal number of Senators from each state, regardless of population. Given this combination of systems, it’s sometimes referred to as a ‘<a target="_blank" href="http://www1.curriculum.edu.au/ddunits/guide/g5b_chart.htm">Washminster</a>‘ system. The election is decided based on how many electorates each party can win such that they can form a majority government. There are currently 150 electorates, so a party requires 76 to gain full control without having to go into talks with the minor parties.</p>
<p>This year, with voting completed and counted (eventually) the Liberal/National Coalition held 76 seats and can govern in their own right. Given that electorates are defined to be of <a target="_blank" href="https://en.wikipedia.org/wiki/Redistribution_(election)#Australia">approximately equal population sizes</a>, this means that the majority of people voted for that party, right? Right? Let’s see.</p>
<p>In terms of open data, Australia doesn’t do too bad. We have a few underutilised resources, such as <a target="_blank" href="http://data.gov.au/">data.gov.au</a> (building an R interface to that site is on my to-do list), <a target="_blank" href="http://www.ands.org.au/">the Australian National Data Service</a>, <a target="_blank" href="https://researchdata.ands.org.au/">Research Data Australia</a>, and <a target="_blank" href="http://www.govpond.org/index.php">GovPond</a>. The <a target="_blank" href="http://www.aec.gov.au/">Australian Electoral Commission</a> (via the <a target="_blank" href="http://vtr.aec.gov.au/HouseDefault-20499.htm">Virtual Tally Room</a>) is one of the better agencies in terms of data availability.</p>
<p>When I visited the <a target="_blank" href="http://vtr.aec.gov.au/HouseDefault-20499.htm">Virtual Tally Room</a> to find out what level of data was available, I was rather impressed to find that the results weren’t only available at the electorate level, but the polling place (‘booth’) level even! Not the individual voters of course, that would be a bit much, but the 7741 polling places around the country with their latitudes/longitudes and votes per party. Not too bad, and certainly an opportunity to look more closely.</p>
<p>This seemed like a good opportunity to try out a <a target="_blank" href="https://github.com/rstudio/flexdashboard/">flexdashboard</a> and the new <a target="_blank" href="https://github.com/rstudio/crosstalk">crosstalk</a> feature. I’ll skip the minor details here and disappoint you early in that I didn’t end up using crosstalk (properly, it’s still in there); it turns out it’s great for subsetting a data set, not so great for performing further aggregations on the data after subsetting. Not to worry.</p>
<p>I managed to grab a <a target="_blank" href="http://www.aec.gov.au/Electorates/gis/gis_datadownload.htm">shapefile of the electorates</a> from the AEC </p>
<p><a target="_blank" href="http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/08/auselectorates-1.png"><img sizes="(max-width: 680px) 100vw, 680px" srcset="http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/08/auselectorates-1.png?w=1716 1716w, http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/08/auselectorates-1.png?resize=300%2C296 300w, http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/08/auselectorates-1.png?resize=768%2C759 768w, http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/08/auselectorates-1.png?resize=1024%2C1011 1024w, http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/08/auselectorates-1.png?resize=228%2C225 228w, http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/08/auselectorates-1.png?w=1360 1360w" alt="auselectorates" class="wp-image-995" src="http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/08/auselectorates-1.png?resize=680%2C672" data-recalc-dims="1"></a></p>
<p>Each of those boxes should <em>roughly</em> contain an equal population of voters. I merged the polling data with these to produce a map of each state with electorates colored by winning party and polling places colored by the party with the most votes. </p>
<p>There’s two caveats to this. Firstly, while we’re required to vote within our electorates (compulsory voting, or at least getting your name ticked off as present) it’s an assumption that people vote at the closest polling place to where they live or work, in which case the distribution of people isn’t biasing the result at each polling place. That might not necessarily be true – perhaps people who vote for a particular party tend towards the city center on election day.</p>
<p>Secondly, there’s no requirement on polling places that they each cater for the same number of people. Electorates are population-balanced, but a polling place could have anywhere from 0 to all of the voters for that electorate show up on that day (we tend to run BBQs at polling places serving up <a target="_blank" href="http://democracysausage.org/">democracy sausages</a>, so people do move around to find the best one). I did try scaling the polling place markers by the number of votes at each but something screwy was going on with the markers disappearing on zoom-changes so I’ve left them all the same.</p>
<div class="wp-caption"><a target="_blank" href="http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/democracysausage.jpg"><img sizes="(max-width: 300px) 100vw, 300px" srcset="http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/democracysausage.jpg?resize=300%2C300 300w, http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/democracysausage.jpg?resize=150%2C150 150w, http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/democracysausage.jpg?resize=225%2C225 225w, http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/democracysausage.jpg?w=384 384w" alt="democracysausage.org" class="wp-image-968" src="http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/democracysausage.jpg?resize=300%2C300" data-recalc-dims="1"></a>
<p class="wp-caption-text">democracysausage.org</p>
</div>
<p>With those in mind, we can now have a look at how polarised each electorate is and compare it to the overall winner. <a target="_blank" href="https://jcarroll.shinyapps.io/AUelection2016/">Here’s the result</a>, hosted over at <a target="_blank" href="http://shinyapps.io/">shinyapps.io</a>. I’ve added a tab for both the first preference votes and two-party preferred (this data isn’t completely available at the time of writing, but I’ll keep updating it).</p>
<p><a target="_blank" href="https://jcarroll.shinyapps.io/AUelection2016/"><img sizes="(max-width: 680px) 100vw, 680px" srcset="http://i2.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/elecFD.png?resize=1024%2C576 1024w, http://i2.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/elecFD.png?resize=300%2C169 300w, http://i2.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/elecFD.png?resize=768%2C432 768w, http://i2.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/elecFD.png?w=1600 1600w, http://i2.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/elecFD.png?w=1360 1360w" alt="elecFD" class="wp-image-981" src="http://i2.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/elecFD.png?resize=680%2C383" data-recalc-dims="1"></a></p>
<p>In my home state of South Australia it’s clear that there’s a big geographical split between the northern and central/southern suburbs</p>
<p><a target="_blank" href="http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/elec1.png"><img sizes="(max-width: 618px) 100vw, 618px" srcset="http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/elec1.png?w=618 618w, http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/elec1.png?resize=300%2C248 300w, http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/elec1.png?resize=272%2C225 272w" alt="elec1" class="wp-image-972" src="http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/elec1.png?resize=618%2C511" data-recalc-dims="1"></a></p>
<p>as well as a clear preference away from the two major parties in the country areas to the East. Voters in the more regional North seemed to not get their way, likely outweighed by the larger population towards the state capital of Adelaide.</p>
<p><a target="_blank" href="http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/elec2.png"><img sizes="(max-width: 629px) 100vw, 629px" srcset="http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/elec2.png?w=629 629w, http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/elec2.png?resize=300%2C242 300w, http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/elec2.png?resize=279%2C225 279w" alt="elec2" class="wp-image-974" src="http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/elec2.png?resize=629%2C507" data-recalc-dims="1"></a></p>
<p>In Tasmania, in the electorate (Denison) that contains the state capital of Hobart, most polling places appear to be overwhelmingly supportive of an independent candidate. </p>
<p><a target="_blank" href="http://i2.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/elec3.png"><img sizes="(max-width: 622px) 100vw, 622px" srcset="http://i2.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/elec3.png?w=622 622w, http://i2.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/elec3.png?resize=300%2C247 300w, http://i2.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/elec3.png?resize=273%2C225 273w" alt="elec3" class="wp-image-973" src="http://i2.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/elec3.png?resize=622%2C513" data-recalc-dims="1"></a></p>
<p>Looking at the number of polling places won, it certainly seems like it was a landslide</p>
<p><a target="_blank" href="http://i2.wp.com/jcarroll.com.au/wp-content/uploads/2016/08/elec4.png"><img sizes="(max-width: 551px) 100vw, 551px" srcset="http://i2.wp.com/jcarroll.com.au/wp-content/uploads/2016/08/elec4.png?w=551 551w, http://i2.wp.com/jcarroll.com.au/wp-content/uploads/2016/08/elec4.png?resize=242%2C300 242w, http://i2.wp.com/jcarroll.com.au/wp-content/uploads/2016/08/elec4.png?resize=181%2C225 181w" alt="elec4" class="wp-image-1001" src="http://i2.wp.com/jcarroll.com.au/wp-content/uploads/2016/08/elec4.png?resize=551%2C684" data-recalc-dims="1"></a></p>
<p>However, the population at just a few polling places showed the fuller story</p>
<p><a target="_blank" href="http://i1.wp.com/jcarroll.com.au/wp-content/uploads/2016/08/elec5.png"><img sizes="(max-width: 544px) 100vw, 544px" srcset="http://i1.wp.com/jcarroll.com.au/wp-content/uploads/2016/08/elec5.png?w=544 544w, http://i1.wp.com/jcarroll.com.au/wp-content/uploads/2016/08/elec5.png?resize=238%2C300 238w, http://i1.wp.com/jcarroll.com.au/wp-content/uploads/2016/08/elec5.png?resize=178%2C225 178w" alt="elec5" class="wp-image-1002" src="http://i1.wp.com/jcarroll.com.au/wp-content/uploads/2016/08/elec5.png?resize=544%2C687" data-recalc-dims="1"></a></p>
<p>In our most populous state of New South Wales, things look fairly consistent within electorates (the dark green here represents the National Party which together with the Liberal party (blue) form the Liberal/National Coalition)</p>
<p><a target="_blank" href="http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/elec6.png"><img sizes="(max-width: 611px) 100vw, 611px" srcset="http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/elec6.png?w=611 611w, http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/elec6.png?resize=300%2C247 300w, http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/elec6.png?resize=273%2C225 273w" alt="elec6" class="wp-image-977" src="http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/elec6.png?resize=611%2C504" data-recalc-dims="1"></a></p>
<p>In Victoria, the state capital of Melbourne fails to shake its hipster stereotype and had quite the clearly defined region of green (our left-wing Greens party)</p>
<p><a target="_blank" href="http://i2.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/elec7.png"><img sizes="(max-width: 634px) 100vw, 634px" srcset="http://i2.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/elec7.png?w=634 634w, http://i2.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/elec7.png?resize=300%2C263 300w, http://i2.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/elec7.png?resize=257%2C225 257w" alt="elec7" class="wp-image-978" src="http://i2.wp.com/jcarroll.com.au/wp-content/uploads/2016/07/elec7.png?resize=634%2C556" data-recalc-dims="1"></a></p>
<p>How about that ‘approximately equal population’ assumption? It’s fairly easy to count up the number of votes in each state/division and compare them</p>
<p><a target="_blank" href="http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/08/elecDivVotes.png"><img sizes="(max-width: 680px) 100vw, 680px" srcset="http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/08/elecDivVotes.png?w=1600 1600w, http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/08/elecDivVotes.png?resize=300%2C150 300w, http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/08/elecDivVotes.png?resize=768%2C384 768w, http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/08/elecDivVotes.png?resize=1024%2C512 1024w, http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/08/elecDivVotes.png?w=1360 1360w" alt="elecDivVotes" class="wp-image-987" src="http://i0.wp.com/jcarroll.com.au/wp-content/uploads/2016/08/elecDivVotes.png?resize=680%2C340" data-recalc-dims="1"></a></p>
<p>It’s clear that ACT, with only two electorates, could in principle divided up more evenly, while the Northern Territory only really has enough people to support one electorate at their current size.</p>
<p>I’ll leave the rest of the exploring to the reader. <a target="_blank" href="https://jcarroll.shinyapps.io/AUelection2016/">Go play with the dashboard and let me know what you find.</a> The <a target="_blank" href="https://github.com/jonocarroll/AUelection2016/blob/master/AUelection2016.Rmd">source code</a> is available either in the header bar or a link in the sidebar. I’m absolutely interested in learning what I perhaps could have done differently/better, so hit me up either in the comments, on <a target="_blank" href="https://github.com/jonocarroll">GitHub</a>, or on <a target="_blank" href="https://twitter.com/carroll_jono">Twitter</a>. </p>
<p><a target="_blank" href="https://github.com/jonocarroll/wp_content/blob/master/_posts/2016-08-01-auelection2016.md">View this post on GitHub</a></p>
<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/2016-australian-federal-election-flexdashboard/"></div></div><div><a data-url="https://www.r-bloggers.com/2016-australian-federal-election-flexdashboard/" data-counturl="https://www.r-bloggers.com/2016-australian-federal-election-flexdashboard/" data-count="vertical" data-text="2016 Australian Federal Election Flexdashboard" 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://jcarroll.com.au/2016/08/01/auelection2016/"> R – Irregularly Scheduled Programming</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/8yjIzspWxGU"></a></div>