<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/population-lines-how-and-why-i-created-it/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://spatial.ly/2017/04/population-lines-how-and-why-i-created-it/"> R – Spatial.ly</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Thanks to the power of <a target="_blank" rel="nofollow" href="https://www.reddit.com/r/MapPorn/comments/66q16g/population_lines_by_dr_james_cheshire_showing/">Reddit</a> the “Population Lines” print (<a target="_blank" rel="nofollow" href="http://spatial.ly/2014/08/population-lines/">buy here</a>) I created back in 2013 has attracted a <em>huge</em> amount of interest in the past week or so (a Europe only version made by Henrik Lindberg made the <a target="_blank" rel="nofollow" href="https://medium.com/@halhen/lessons-learned-from-putting-an-erroneous-visualization-on-reddits-front-page-998bc3c62116">Reddit front page</a>). There’s been lots of subsequent discussion about it’s inspiration, effectiveness as a form of visualisation and requests for the original code. So for the purposes of posterity I thought I’d run through the map’s conception and history.</p>
<p><img sizes="(max-width: 1000px) 100vw, 1000px" alt="" class="wp-image-5904" src="https://i2.wp.com/spatial.ly/wp-content/uploads/2017/04/IMG_5342.jpg?resize=3024%2C4032" data-recalc-dims="1"></p>
<p>I was asked to create a graphic for the front cover for the programme of the Royal Geographical Society’s Annual Conference in 2013. The theme for the conference was “New Geographical Frontiers” and given the RGS’s long association with exploration I immediately thought of path breaking across undiscovered lands or summiting mountains. These activities have very little to do with the annual conference, but I wanted to evoke them a little on the cover. To me the greatest frontier for geographers is better understanding the world population and also appreciating that Europe/ the USA are no longer at the centre of the action. I therefore played around with various population map options (you can see some inspiration ideas <a target="_blank" rel="nofollow" href="http://spatial.ly/2013/10/mapping-where-we-live/">here</a>). I was keen to get something that showed the true peaks of global population, which is how I came upon what I thought was a fairly original idea of showing population density spikes along lines of latitude using data from <a target="_blank" rel="nofollow" href="http://sedac.ciesin.columbia.edu/">NASA’s SEDAC</a>. After creating this – and as with so many things in geography/cartography/ dataviz – I later discovered that mapping spatial data in this way had been done before by the pioneers of computer mapping using software called <a target="_blank" rel="nofollow" href="https://en.wikipedia.org/wiki/Harvard_Laboratory_for_Computer_Graphics_and_Spatial_Analysis">SYMAP</a> (I can’t find an image of this but I’ve definitely seen it!). So it’s nothing new in terms of a way of geographically representing the world.</p>
<p>As for the design I was seeking something akin to the iconic Joy Division <a target="_blank" rel="nofollow" href="https://en.wikipedia.org/wiki/Unknown_Pleasures">album cover</a>. The original RGS cover was black and white, but thanks to a suggestion from <a target="_blank" rel="nofollow" href="http://www.oliveruberti.com/">Oliver</a>, I opted to mark key cities in gold to help with orientation etc. I’ve provided the original R code below for those interested. Since creating <a target="_blank" rel="nofollow" href="http://spatial.ly/2014/08/population-lines/">Population Lines</a> I’ve only created one other map using this technique and it was for the book <a target="_blank" rel="nofollow" href="https://www.amazon.co.uk/LONDON-Information-Capital-graphics-change/dp/0141978791/ref=as_li_ss_tl?_encoding=UTF8&qid=&sr=&linkCode=ll1&tag=spatialanalys-21&linkId=fe304eba18faf019f217cbd48b2325c3">London: the Information Capital</a>. For this we wanted to show the huge population spike experienced but The City of London during the working day. I think it works really well for this. I’m not convinced the technique is good at showing exact data values at precise locations but if you are looking to draw attention to extremes and you are dealing with familiar geographies/ places then it can tell a compelling story.</p>
<h2><img sizes="(max-width: 1000px) 100vw, 1000px" alt="" class="wp-image-5906" src="https://i1.wp.com/spatial.ly/wp-content/uploads/2017/04/day_night_london_information_capital.jpg?resize=2416%2C4032" data-recalc-dims="1">R Code</h2>
<p>Here is the original R code I used back in May 2013. R has come on a lot since then, but this still works! You should use the latest population grid from <a target="_blank" rel="nofollow" href="http://sedac.ciesin.columbia.edu/data/set/gpw-v4-population-count">NASA’s SEDAC</a>.</p>
<p> </p>
<pre><code>#Load packages
library(sp)
library(rgdal)
library(reshape)
library(ggplot2)
library(maptools)
library(rgeos)</code> <code>#create a range standardisation function
range01 &lt;- function(x){(x-min(x))/(max(x)-min(x))}


#load in a population grid - in this case it's population density from NASA's SEDAC (see link above). It's spatial data if you haven't seen this before in R.
input&lt;-readGDAL(&quot;glp10ag30.asc&quot;) # the latest data come as a Tiff so you will need to tweak.</code></pre>
<pre><code>## glp10ag30.asc has GDAL driver AAIGrid 
## and has 286 rows and 720 columns</code></pre>
<pre><code>proj4string(input) = CRS(&quot;+init=epsg:4326&quot;)</code></pre>
<pre><code>## Warning in `proj4string&lt;-`(`*tmp*`, value = &lt;S4 object of class structure(&quot;CRS&quot;, package = &quot;sp&quot;)>): A new CRS was assigned to an object with an existing CRS:
## +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
## without reprojecting.
## For reprojection, use function spTransform</code></pre>
<pre><code>#Get the data out of the spatial grid format using &quot;melt&quot; and rename the columns.
values&lt;-melt(input)
names(values)&lt;- c(&quot;pop&quot;, &quot;x&quot;, &quot;y&quot;)

#Rescale the values. This is to ensure that you can see the variation in the data
values$pop_st&lt;-range01(values$pop)*0.20
values$x_st&lt;-range01(values$x)
values$y_st&lt;-range01(values$y)

#Switch off various ggplot things

xquiet&lt;- scale_x_continuous(&quot;&quot;, breaks=NULL)
yquiet&lt;-scale_y_continuous(&quot;&quot;, breaks=NULL)
quiet&lt;-list(xquiet, yquiet)

#Add 180 to the latitude to remove negatives in southern hemisphere, then order them.
values$ord&lt;-values$y+180
values_s&lt;- values[order(-values$ord),]

#Create an empty plot called p
p&lt;-ggplot()

#This loops through each line of latitude and produced a filled polygon that will mask out the lines beneath and then plots the paths on top.The p object becomes a big ggplot2 plot.
for (i in unique(values_s$ord))
{
p&lt;-p+geom_polygon(data=values_s[values_s$ord==i,],aes(x_st, pop_st+y_st,group=y_st), size=0.2, fill=&quot;white&quot;, col=&quot;white&quot;)+ geom_path(data=values_s[values_s$ord==i,],aes(x_st, pop_st+y_st,group=y_st),size=0.2, lineend=&quot;round&quot;)
}

#show plot!
p +theme(panel.background = element_rect(fill='white',colour='white'))+quiet</code></pre>
<p>If you want to learn more, you can see here for another <a target="_blank" rel="nofollow" href="http://www.whackdata.com/2014/08/04/line-graphs-parallel-processing-r/">tutorial</a> that takes a slightly different approach with the same effect.</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="http://spatial.ly/2017/04/population-lines-how-and-why-i-created-it/"> R – Spatial.ly</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/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/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/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/lnqL1Sq85pk"></a></div>