<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/surprising-stories-hide-in-seemingly-mundane-data/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://thinkr.biz/2017/12/20/geospatial/"> R – thinkr</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<h2>Geospatial experimentation</h2>
<p>Recently I experimented with geospatial mapping techniques in R.  I looked at both static and interactive maps. Embedding the media into a WordPress blog would be simple enough with a static map. The latter would require (for me) a new technique to retain the interactivity inside a blog post.</p>
<p>My web-site visitor log, combined with longitude and latitude data from <a rel="nofollow" href="https://dev.maxmind.com/geoip/geoip2/geolite2/" target="_blank">MaxMind’s GeoLite2</a>, offered a basis for analysis. Although less precise than the GeoIP2 database, this would be more than adequate for my purpose of getting to country and city level.  I settled on the Leaflet package for visualisation given the interactivity and pleasing choice of aesthetics.</p>
<p>The results however were a little puzzling.<br>
<span></span></p>
<p><br>
<iframe src="https://thinkr.biz/wp-content/uploads/2017/12/world.html" width="100%" height="370"></iframe></p>
<h2>Whiling away the hours in Kansas</h2>
<p>The concentration of page views in central London was of no immediate surprise as this was likely to be my site building, testing, and blogging. What did strike me as odd was the high concentration of page views in the centre of the US. More curious still, when I zoomed in on Kansas and found myself in the middle of the Cheney Reservoir.</p>
<figure class="wp-caption"><img sizes="(max-width: 690px) 100vw, 690px" src="https://i2.wp.com/thinkr.biz/wp-content/uploads/2017/12/Cheney.png?w=450&ssl=1" alt="Non-interactive image of the Cheney Reservoir in Kansas, US" class="wp-image-381" data-recalc-dims="1"><figcaption class="wp-caption-text">Non-interactive image of the Cheney Reservoir in Kansas, US</figcaption></figure>
<p>I imagined someone drifting in the expanse of water with laptop, flask of coffee and box of sandwiches, whiling away the hours absorbed in my blog.  Perhaps not. How could such a small number of blog pages generate in excess of 2,000 page views in less than two months?</p>
<p>Then I chanced upon a <a rel="nofollow" href="http://www.bbc.com/news/technology-37048521" target="_blank">BBC news article from August 2016</a>. When unable to locate IPs, MaxMind chose the geographical centre of the US as a default. This initially turned out to be a rented house in Kansas, which was rather unfortunate for the occupants, and brought upon them all kinds of unwanted attention.</p>
<p>MaxMind subsequently changed its default centre points to be the middle of bodies of water. And this solved another puzzle. Some of the page views in London appeared to be in the middle of the River Thames.</p>
<h2>R tools used</h2>
<table>
<thead>
<tr>
<th> </th>
<th><strong>Packages</strong></th>
<th><strong>Functions</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td><img alt="" src="https://i1.wp.com/thinkr.biz/wp-content/uploads/2017/10/Program-e1509478672361.png?resize=100%2C100&ssl=1" class="wp-image-135" data-recalc-dims="1"></td>
<td>purrr</td>
<td>map_df</td>
</tr>
<tr>
<td rowspan="3"><img alt="" src="https://i0.wp.com/thinkr.biz/wp-content/uploads/2017/10/Import-e1509478685299.png?resize=100%2C100&ssl=1" class="wp-image-134" data-recalc-dims="1"></td>
<td>readr</td>
<td>read_csv</td>
</tr>
<tr>
<td>rgeolocate</td>
<td>maxmind</td>
</tr>
<tr>
<td>rgdal</td>
<td>readOGR	</td>
</tr>
<tr>
<td rowspan="2"><img alt="" src="https://i2.wp.com/thinkr.biz/wp-content/uploads/2017/10/Transform-e1509478657749.png?resize=100%2C100&ssl=1" class="wp-image-136" data-recalc-dims="1"></td>
<td>dplyr</td>
<td>inner_join; mutate; arrange; if_else</td>
</tr>
<tr>
<td>stringr</td>
<td>str_c</td>
</tr>
<tr>
<td rowspan="2"><img alt="" src="https://i1.wp.com/thinkr.biz/wp-content/uploads/2017/10/Visualize-e1509478640644.png?resize=100%2C100&ssl=1" class="wp-image-137" data-recalc-dims="1"></td>
<td>leaflet</td>
<td>colorFactor; addProviderTiles; setView; addPolygons; addCircleMarkers; addLegend</td>
</tr>
<tr>
<td>htmlwidgets</td>
<td>saveWidget</td>
</tr>
</tbody>
</table>
<p></p>
<p><a rel="nofollow" href="https://thinkr.biz/geospatial-code/" target="_blank">The code may be viewed here</a>.</p>
<h3>WordPress integration</h3>
<ol>
<li>Install the WordPress plugin <a rel="nofollow" href="https://wordpress.org/plugins/iframe/" target="_blank">iframe</a>.</li>
<li>Upload the htmlwidget (created in R) to the WordPress media library.</li>
<li>Embed the following shortcode in the WordPress post (ensuring it’s wrapped in square brackets, and replacing <em>xxx</em> with the path of the uploaded media file): <em>iframe src=”xxx” width=”100%” height=”370″</em>.</li>
</ol>
<h3>Citations / Attributions</h3>
<p>Includes GeoLite2 data created by MaxMind, available from <a rel="nofollow" href="http://www.maxmind.com/" target="_blank"><span><span>http://www.maxmind.com</span></span></a>.</p>
<p>Map tiles by <a rel="nofollow" href="http://stamen.com/" target="_blank">Stamen Design</a>, <a rel="nofollow" href="http://creativecommons.org/licenses/by/3.0" target="_blank">CC BY 3.0</a> — Map data © <a rel="nofollow" href="http://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a></p>
<p><a rel="nofollow" href="http://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> © <a rel="nofollow" href="http://cartodb.com/attributions" target="_blank">CartoDB</a></p>
<p>World borders dataset provided by <a rel="nofollow" href="http://thematicmapping.org/downloads/world_borders.php" target="_blank">thematic mapping.org</a>.</p>
<p>The post <a rel="nofollow" href="https://thinkr.biz/2017/12/20/geospatial/" target="_blank">Surprising stories hide in seemingly mundane data</a> appeared first on <a rel="nofollow" href="https://thinkr.biz/" target="_blank">thinkr</a>.</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://thinkr.biz/2017/12/20/geospatial/"> R – thinkr</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/aop2bEvb1yQ" height="1"></a></div>