<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/edward-tuftes-slopegraphs-and-political-fortunes-in-ontario/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://ekonometrics.blogspot.com/2018/05/edward-tuftes-slopegraphs-and-political.html"> eKonometrics</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<div dir="ltr">
<div><span>With fewer than three weeks left in the June 7 provincial elections in Ontario, Canada’s most populous province with 14.2 million persons, the expected outcome is far from certain.</span></div>
<div></div>
<div></div>
<div>The weekly opinion polls reflect the volatility in public opinion. Progressive Conservatives (PC), one of the main opposition parties, is in the lead with the support of roughly 40 percent of the electorate. The incumbent Ontario Liberals are trailing with their support hanging around lower 20 percent.</div>
<div></div>
<div>The real story in these elections is the unexpected rise in the fortunes of the New Democratic Party (NDP) that has seen a sustained increase in its popularity from less than 20 percent a few weeks ago to mid 30 percent.</div>
<div></div>
<div>As a data scientist/journalist, I have been concerned with how best to represent this information. A scatter plot of sorts would do. However, I would like to demonstrate the change in political fortunes over time with the x-axis representing time. Hence, a time series chart would be more appropriate.</div>
<div></div>
<div>Ideally, I would like to plot what Edward Tufte called a <a rel="nofollow" href="https://www.edwardtufte.com/bboard/q-and-a-fetch-msg?msg_id=0003nk" target="_blank">Slopegraph</a>. Tufte, in his 1983 book <i>The Visual Display of Quantitative Information</i>, explained that “Slopegraphs compare changes usually over time for a list of nouns located on an ordinal or interval scale”. </div>
<div></div>
<div>But here’s the problem. No software offers a readymade solution to draw a Slopegraph.</div>
<div></div>
<div>Luckily, I found a way, in fact, two ways, around the challenge with help from colleagues at <a rel="nofollow" href="http://www.stata.com/" target="_blank">Stata</a> and R (<a rel="nofollow" href="https://cran.r-project.org/web/packages/plotrix/index.html" target="_blank">plotrix</a>).</div>
<div></div>
<div>So, what follows in this blog is the story of the elections in Ontario described with data visualized as Slopegraphs. I tell the story first with Stata and then with the <a rel="nofollow" href="https://cran.r-project.org/web/packages/plotrix/index.html" target="_blank">plotrix</a> package in R.</div>
<div></div>
<div>My interest grew in Slopegraphs when I wanted to demonstrate the steep increase in highly leveraged mortgage loans in Canada from 2014 to 2016. I generated the chart in Excel and sent it to Stata requesting help to recreate it. </div>
<div></div>
<div>Stata assigned my request to <a rel="nofollow" href="https://www.linkedin.com/in/derek-wagner-127b033/" target="_blank">Derek Wagner</a> whose excellent programming skills resulted in the following chart.</div>
<div></div>
<div><a rel="nofollow" href="https://i1.wp.com/3.bp.blogspot.com/-bu8kz5QzAdw/WwLT-k5nceI/AAAAAAAAHLI/T3XNpLaEOToljwN-pb7_mWrwHtwQohvBACEwYBhgL/s1600/mortgage.png?ssl=1" target="_blank"><img border="0" src="https://i1.wp.com/3.bp.blogspot.com/-bu8kz5QzAdw/WwLT-k5nceI/AAAAAAAAHLI/T3XNpLaEOToljwN-pb7_mWrwHtwQohvBACEwYBhgL/s400/mortgage.png?resize=450%2C637&ssl=1" data-original-width="450" width="450" data-original-height="637" data-recalc-dims="1"></a></div>
<div></div>
<div></div>
<div>Derek built the chart on the <a rel="nofollow" href="https://www.stata.com/statalist/archive/2003-07/msg00194.html" target="_blank">linkplot</a> command built by the uber Stata guru, Professor <a rel="nofollow" href="https://www.dur.ac.uk/geography/staff/geogstaffhidden/?id=335" target="_blank">Nicholas J. Cox</a>. However, a straightforward application of linkplot still required a lot of tweaks that Derek very ably managed. For comparison, see the initial version of the chart generated by linkplot below.</div>
<div></div>
<div><a rel="nofollow" href="https://i0.wp.com/4.bp.blogspot.com/-E7t2VhcqCjQ/WwLUU30pdpI/AAAAAAAAHLQ/E0D7-1O7kZct47oEDNQTyaQICgKDOX5dACLcBGAs/s1600/linkplot.png?ssl=1" target="_blank"><img border="0" src="https://i0.wp.com/4.bp.blogspot.com/-E7t2VhcqCjQ/WwLUU30pdpI/AAAAAAAAHLQ/E0D7-1O7kZct47oEDNQTyaQICgKDOX5dACLcBGAs/s400/linkplot.png?resize=450%2C512&ssl=1" data-original-width="450" width="450" data-original-height="512" data-recalc-dims="1"></a></div>
<div></div>
<div></div>
<div> </div>
<div>We made the following modifications to the base linkplot:</div>
<div></div>
<div>1.<span>    </span>Narrow the plot by reducing the space between the two time periods.</div>
<div>2.<span>    </span>Label the entities and their respective values at the primary and secondary y-axes. </div>
<div>3.<span>    </span>Add a title and footnotes (if necessary). </div>
<div>4.<span>    </span>Label time periods with custom names.</div>
<div>5.<span>    </span>Colour lines and symbols to match preferences.</div>
<div></div>
<div>Once we apply these tweaks a Slopegraph with the latest poll data for Ontario’s election is drawn as follows.</div>
<div></div>
<div><a rel="nofollow" href="https://i1.wp.com/2.bp.blogspot.com/-2R-mJvu1T44/WwLUa7Blu4I/AAAAAAAAHLk/Sa9EoZWFxMAx3c7UmPHzYCaquTVL9sRHQCEwYBhgL/s1600/Abacus%2Bstata.png?ssl=1" target="_blank"><img border="0" src="https://i2.wp.com/2.bp.blogspot.com/-2R-mJvu1T44/WwLUa7Blu4I/AAAAAAAAHLk/Sa9EoZWFxMAx3c7UmPHzYCaquTVL9sRHQCEwYBhgL/s400/Abacus%2Bstata.png?resize=450%2C701&ssl=1" data-original-width="450" width="450" data-original-height="701" data-recalc-dims="1"></a></div>
<div></div>
<div>Notice that in fewer than two weeks, NDP has jumped from 29 percent to 34 percent, almost tying up with the leading PC party whose support has remained steady at 35 percent. The incumbent Ontario Liberals appear to be in free fall from 29 percent to 24 percent.</div>
<div></div>
<div></div>
<div>I must admit that I have sort of cheated in the above chart. Note that both Liberals and NDP secured 29 percent of the support in the poll conducted on May 06. In the original chart drawn with Stata’s code, their labels overlapped resulting in unintelligible text. I fixed this manually by manipulating the image in PowerPoint.</div>
<div></div>
<div>I wanted to replicate the above chart in R. I tried a few packages, but nothing really worked until I landed on the plotrix package that carries the bumpchart command. In fact, Edward Tufte in <i>Beautiful Evidence</i> (2006) mentions that bumpcharts may be considered as slopegraphs.</div>
<div></div>
<div>A straightforward application of bumpchart from the plotrix package labelled the party names but not the respective percentages of support each party commanded.</div>
<div></div>
<div><a rel="nofollow" href="https://www.r-pkg.org/maint/drjimlemon@gmail.com" target="_blank">Dr. Jim Lemon</a> authored bumpchart. I turned to him for help. Jim was kind enough to write a custom function, bumpchart2, that I used to create a Slopegraph like the one I generated with Stata. For comparison, see the chart below.</div>
<div></div>
<div><a rel="nofollow" href="https://i1.wp.com/1.bp.blogspot.com/-V8c8tDpy05A/WwLUcKdWvhI/AAAAAAAAHLg/PeH_OJyMm10HsL1kCEICQF6Ia29snWaewCEwYBhgL/s1600/Abacus%2Bplotrix.png?ssl=1" target="_blank"><img border="0" src="https://i1.wp.com/1.bp.blogspot.com/-V8c8tDpy05A/WwLUcKdWvhI/AAAAAAAAHLg/PeH_OJyMm10HsL1kCEICQF6Ia29snWaewCEwYBhgL/s400/Abacus%2Bplotrix.png?resize=450%2C904&ssl=1" data-original-width="450" width="450" data-original-height="904" data-recalc-dims="1"></a></div>
<div></div>
<div></div>
<div>As with the Slopegraph generated with Stata, I manually manipulated the labels to prevent NDP and Liberal labels from overlapping.</div>
<div></div>
<h2>Data Scientist must dig even deeper</h2>
<p>The job of a data scientist, unlike a computer scientist or a statistician, is not done by estimating models and drawing figures. A data scientist must tell a story with all caveats that might apply. So, here’s the story about what can go wrong with polls.</p>
<div></div>
<div></div>
<div>The most important lesson about forecasting from Brexit and the last US Presidential elections is that one cannot rely on polls to determine the future electoral outcomes. Most polls in the UK predicted a NO vote for Brexit. In the US, most polls forecasted Hillary Clinton to be the winner. Both forecasts went horribly wrong. </div>
<div></div>
<div>When it comes to polls, one must determine who sponsored the poll, what methods were used, and how representative is the sample of the underlying population. Asking the wrong question to the right people or posing the right question to the wrong people (non-representative sample) can deliver problematic results. </div>
<div></div>
<div>Polling is as much science as it is arts. Late <a rel="nofollow" href="https://www.nytimes.com/2006/09/04/obituaries/04mitofsky.html" target="_blank">Warren Mitofsky</a>, who pioneered exit polls and innovated political survey research, remains a legend in political polling. His painstakingly cautious approach to polling is why he remains a respected name in market research. </div>
<div></div>
<div>Today, the advances in communication and information technologies have made survey research easier to conduct but more difficult to be precise. No longer can one rely on random digit dialling, a Mitosky innovation, to reach a representative sample. Younger cohorts sparingly subscribe to land telephone lines. The attempts to catch them online poses the risk of fishing for opinions in echo chambers.</div>
<div></div>
<div>Add political polarization to technological challenges, and one realizes the true scope of the difficulties inherent in the task of taking the political pulse of an electorate where motivated pollster may be after not the truth, but a convenient version of it.</div>
<div></div>
<div>Polls also differ by survey instrument, methodology, and sample size. The Abacus Data poll presented above is essentially an online poll of 2,326 respondents. In comparison, a poll by Mainstreet Research used Interactive Voice Response (IVR) system with a sample size of 2,350 respondents. IVR uses automated computerized responses over the telephone to record responses.</div>
<div></div>
<div>Abacus Data and Mainstreet Research use quite different methods with similar sample sizes. Professor Dan Cassino of Fairleigh Dickinson University explained the challenges with polling techniques in a 2016 article in the <a rel="nofollow" href="https://hbr.org/2016/08/how-todays-political-polling-works" target="_blank">Harvard Business Review</a>. He favours live telephone interviewers who “are highly experienced and college educated and paying them is the main cost of political surveys.”  </div>
<div></div>
<div>Professor Cassino believes that techniques like IVR make “polling faster and cheaper,” but these systems are hardly foolproof with lower response rates. They cannot legally reach cellphones. “IVR may work for populations of older, whiter voters with landlines, such as in some Republican primary races, but they’re not generally useful,” explained Professor Cassino. </div>
<div></div>
<div>Similarly, online polls are limited in the sense that in the US alone 16 percent Americans don’t use the Internet. </div>
<div></div>
<div>With these caveats in mind, a plot of Mainstreet Research data reveals quite a different picture where the NDP doesn’t seem to pose an immediate and direct challenge to the PC party.</div>
<div></div>
<div>So, here’s the summary. Slopegraph is a useful tool to summarize change over time between distinct entities. Ontario is likely to have a new government on June 7. It is though, far from being certain whether the PC Party or NDP will assume office. Nevertheless, Slopergaphs generate visuals that expose the uncertainty in the forthcoming elections.</div>
<div></div>
<div><a rel="nofollow" href="https://i0.wp.com/1.bp.blogspot.com/-JOkwco53x5U/WwLUdcP-YCI/AAAAAAAAHLk/I01WuHmmEYE38M-0KqpuFvhRHpf13ajLACEwYBhgL/s1600/Mainstreet%2BResearch.png?ssl=1" target="_blank"><img border="0" src="https://i1.wp.com/1.bp.blogspot.com/-JOkwco53x5U/WwLUdcP-YCI/AAAAAAAAHLk/I01WuHmmEYE38M-0KqpuFvhRHpf13ajLACEwYBhgL/s400/Mainstreet%2BResearch.png?resize=450%2C772&ssl=1" data-original-width="450" width="450" data-original-height="772" data-recalc-dims="1"></a></div>
<div></div>
<div></div>
<div>Note: To generate the charts in this blog, you can download data and code for Stata and Plotrix (R) by <a rel="nofollow" href="https://sites.google.com/site/statsr4us/analytics/graphics/linkplot%20and%20bumpchart2%20codes.txt" target="_blank">clicking HERE</a>.</div>
<p></p>
<div></div>
</div>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://ekonometrics.blogspot.com/2018/05/edward-tuftes-slopegraphs-and-political.html"> eKonometrics</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 width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/CmQuWxKEIxs" height="1"></a></div>