<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/just-use-a-scatterplot-also-sydney-sprawls/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://nsaunders.wordpress.com/2018/07/18/just-use-a-scatterplot-also-sydney-sprawls/"> 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><div data-shortcode="caption" class="wp-caption"><a rel="nofollow" href="https://nsaunders.files.wordpress.com/2018/07/sydney-traffic-city-congestion-at-tipping-point.png" target="_blank"><img data-orig-file="https://nsaunders.files.wordpress.com/2018/07/sydney-traffic-city-congestion-at-tipping-point.png" data-orig-size="1596,1058" data-medium-file="https://nsaunders.files.wordpress.com/2018/07/sydney-traffic-city-congestion-at-tipping-point.png?w=300&amp;h=199&amp;fit=300%2C199&amp;resize=300%2C199" data-attachment-id="5103" data-image-meta="{" data-image-description="" src="https://nsaunders.files.wordpress.com/2018/07/sydney-traffic-city-congestion-at-tipping-point.png?w=300&h=199&fit=300%2C199&resize=300%2C199" data-permalink="https://nsaunders.wordpress.com/2018/07/18/just-use-a-scatterplot-also-sydney-sprawls/sydney-traffic-city-congestion-at-tipping-point/" data-large-file="https://nsaunders.files.wordpress.com/2018/07/sydney-traffic-city-congestion-at-tipping-point.png?w=1024" alt="" data-image-title="Sydney traffic: City congestion at ‘tipping point’" sizes="(max-width: 300px) 100vw, 300px" width="300" data-comments-opened="1" class="wp-image-5103" data-recalc-dims="1" height="199"></a>
<p class="wp-caption-text">Dual-axes at tipping-point</p>
</div>
<p><a rel="nofollow" href="https://www.smh.com.au/national/nsw/sydney-s-congestion-at-tipping-point-20180520-p4zgfq.html" target="_blank">Sydney’s congestion at ‘tipping point’</a> blares the headline and to illustrate, an interactive chart with bars for city population densities, points for commute times and of course, dual-axes.</p>
<p>Yuck. OK, I guess it does show that Sydney is one of three cities that are low density, but have comparable average commute times to higher-density cities. But if you’re plotting commute time versus population density…doesn’t a different kind of chart come to mind first? <em>y versus x</em>. C’mon.</p>
<p>Let’s explore.<br>
<span></span></p>
<p>First: do we even believe the numbers? Comments on the article point out that the population density for Phoenix was corrected after publication, and question the precise meaning of city area. Hovering over the graphic to obtain the values, then visiting Wikipedia’s city pages, we can create a Google spreadsheet which I hope is <a rel="nofollow" href="https://docs.google.com/spreadsheets/d/1JrOYsHx4fJAEVA8XvO5ey-Ud-tumX9RA-xiAvLyPFWM/edit?usp=sharing" target="_blank">publicly-visible at this link</a>. Here’s a graphical summary.</p>
<p><a rel="nofollow" href="https://nsaunders.files.wordpress.com/2018/07/city_commutes.png" target="_blank"><img data-orig-file="https://nsaunders.files.wordpress.com/2018/07/city_commutes.png" data-orig-size="1576,286" data-medium-file="https://nsaunders.files.wordpress.com/2018/07/city_commutes.png?w=300" data-attachment-id="5113" data-image-meta="{" data-image-description="" src="https://nsaunders.files.wordpress.com/2018/07/city_commutes.png?w=1024&h=186&fit=456%2C456" data-permalink="https://nsaunders.wordpress.com/2018/07/18/just-use-a-scatterplot-also-sydney-sprawls/city_commutes/" data-large-file="https://nsaunders.files.wordpress.com/2018/07/city_commutes.png?w=1024" alt="" data-image-title="city_commutes" sizes="(max-width: 1024px) 100vw, 1024px" data-comments-opened="1" class="wp-image-5113" data-recalc-dims="1"></a></p>
<p>It looks like the figures for population density used in the article (<em>smh_density</em>) correspond roughly to metro population divided by metro area (<em>metro_density</em>). We’ll come back to whether population density is a good predictor or comparator later.</p>
<p>Let’s think about how this data was visualised in the article. We have cities, each of which has two measurements: population density and average commute time. Bars for density, labelled with city name. Points for commute time, aligned with the bars. A y-axis for each measurement. Result: ugly.</p>
<p>Presumably the authors wanted to answer the question “how is commute time related to population density?” So why not just plot one versus the other?</p>
<ul>
<li>Plot population density (x) versus average commute time as a scatterplot</li>
<li>Label each point with the city name</li>
<li>Optionally: draw attention to the values using size and/or colour</li>
<li>Optionally: add a summary statistic (mean, median) </li>
</ul>
<p>Let’s do that and in addition, showcase the wonderful googlesheets R package, to import the Google sheet straight into R.</p>
<pre>
library(googlesheets)
library(tidyverse)

city_commutes &lt;- gs_url(&quot;https://docs.google.com/spreadsheets/d/1JrOYsHx4fJAEVA8XvO5ey-Ud-tumX9RA-xiAvLyPFWM/edit?usp=sharing&quot;) %>% 
  gs_read()

city_commutes %>% 
  ggplot(aes(smh_density, smh_commute)) + 
  geom_point(aes(size = smh_commute, color = smh_density)) + 
  guides(size = FALSE, color = FALSE) + 
  geom_text(aes(label = city), vjust = -0.9, hjust = 0.74) + 
  labs(x = &quot;Density (people per sq. km)&quot;, 
       y = &quot;Average commute time (min)&quot;, 
       title = &quot;Average one-way commute time versus population density&quot;, 
       subtitle = &quot;Dashed lines indicate median values for the dataset&quot;) + 
  geom_hline(aes(yintercept = median(smh_commute)), 
             linetype = &quot;dashed&quot;, 
             color = &quot;darkred&quot;) + 
  geom_vline(aes(xintercept = median(smh_density)), 
             linetype = &quot;dashed&quot;, 
             color = &quot;darkred&quot;) +
  theme_bw() + 
  scale_color_viridis_c()
</pre>
<p>Result. I’d argue that Sydney’s position as “low-density, high commute time” is apparent. You might also make statements such as “Sydney and San Francisco have comparable commute times to Toronto, despite having much lower population densities.”</p>
<p>Phoenix is just a weird outlier; I don’t know why it was even included in the original article.</p>
<p><a rel="nofollow" href="https://nsaunders.files.wordpress.com/2018/07/city_commutes01.png" target="_blank"><img data-orig-file="https://nsaunders.files.wordpress.com/2018/07/city_commutes01.png" data-orig-size="1024,595" data-medium-file="https://nsaunders.files.wordpress.com/2018/07/city_commutes01.png?w=300" data-attachment-id="5117" data-image-meta="{" data-image-description="" src="https://nsaunders.files.wordpress.com/2018/07/city_commutes01.png?w=1024&h=595&fit=456%2C456" data-permalink="https://nsaunders.wordpress.com/2018/07/18/just-use-a-scatterplot-also-sydney-sprawls/city_commutes01/" data-large-file="https://nsaunders.files.wordpress.com/2018/07/city_commutes01.png?w=1024" alt="" data-image-title="city_commutes01" sizes="(max-width: 1024px) 100vw, 1024px" data-comments-opened="1" class="wp-image-5117" data-recalc-dims="1"></a></p>
<p>But wait. Back to the table of values. Note that Wikipedia provides population density figures for all cities (<em>wp_density</em>). For most of the cities, this value is calculated as <em>city_pop / city_area</em>. <strong>Except for Sydney</strong>, where it is calculated as <em>metro_pop / metro_area</em>. If we plot commute time versus <em>wp_density</em>, things look rather different.</p>
<p><a rel="nofollow" href="https://nsaunders.files.wordpress.com/2018/07/city_commutes02.png" target="_blank"><img data-orig-file="https://nsaunders.files.wordpress.com/2018/07/city_commutes02.png" data-orig-size="1024,595" data-medium-file="https://nsaunders.files.wordpress.com/2018/07/city_commutes02.png?w=300" data-attachment-id="5121" data-image-meta="{" data-image-description="" src="https://nsaunders.files.wordpress.com/2018/07/city_commutes02.png?w=1024&h=595&fit=456%2C456" data-permalink="https://nsaunders.wordpress.com/2018/07/18/just-use-a-scatterplot-also-sydney-sprawls/city_commutes02/" data-large-file="https://nsaunders.files.wordpress.com/2018/07/city_commutes02.png?w=1024" alt="" data-image-title="city_commutes02" sizes="(max-width: 1024px) 100vw, 1024px" data-comments-opened="1" class="wp-image-5121" data-recalc-dims="1"></a></p>
<p>And if we drop Phoenix from the dataset, Sydney stands all alone – but note that the range of average commute time is only about 5 minutes.</p>
<p><a rel="nofollow" href="https://nsaunders.files.wordpress.com/2018/07/city_commutes03.png" target="_blank"><img data-orig-file="https://nsaunders.files.wordpress.com/2018/07/city_commutes03.png" data-orig-size="1024,595" data-medium-file="https://nsaunders.files.wordpress.com/2018/07/city_commutes03.png?w=300" data-attachment-id="5122" data-image-meta="{" data-image-description="" src="https://nsaunders.files.wordpress.com/2018/07/city_commutes03.png?w=1024&h=595&fit=456%2C456" data-permalink="https://nsaunders.wordpress.com/2018/07/18/just-use-a-scatterplot-also-sydney-sprawls/city_commutes03/" data-large-file="https://nsaunders.files.wordpress.com/2018/07/city_commutes03.png?w=1024" alt="" data-image-title="city_commutes03" sizes="(max-width: 1024px) 100vw, 1024px" data-comments-opened="1" class="wp-image-5122" data-recalc-dims="1"></a></p>
<p>What I think the data are really telling us is that Sydney thinks its city area is “all of Sydney”, whereas European and North American cities define city area differently. It’s not surprising then, that commute time compares unfavourably, since the population density value for Sydney is artificially low and not comparable with the other cities. We can make this apparent by plotting against metro area instead.</p>
<p><a rel="nofollow" href="https://nsaunders.files.wordpress.com/2018/07/city_commutes041.png" target="_blank"><img data-orig-file="https://nsaunders.files.wordpress.com/2018/07/city_commutes041.png" data-orig-size="1024,595" data-medium-file="https://nsaunders.files.wordpress.com/2018/07/city_commutes041.png?w=300" data-attachment-id="5127" data-image-meta="{" data-image-description="" src="https://nsaunders.files.wordpress.com/2018/07/city_commutes041.png?w=1024&h=595&fit=456%2C456" data-permalink="https://nsaunders.wordpress.com/2018/07/18/just-use-a-scatterplot-also-sydney-sprawls/city_commutes04-2/" data-large-file="https://nsaunders.files.wordpress.com/2018/07/city_commutes041.png?w=1024" alt="" data-image-title="city_commutes04" sizes="(max-width: 1024px) 100vw, 1024px" data-comments-opened="1" class="wp-image-5127" data-recalc-dims="1"></a></p>
<p>This makes more intuitive sense. If you’re further away your commute takes longer. Unless you’re in Los Angeles, which is all big roads.</p>
<p>In conclusion:</p>
<ul>
<li>Scatterplots – good</li>
<li>News article’s interpretation of factors affecting commute time – poor</li>
</ul>
	<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/2018/07/18/just-use-a-scatterplot-also-sydney-sprawls/"> 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/0Ppf4rovsbc" height="1"></a></div>