<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/finding-antipodes-using-the-globe-and-ggmap-packages/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://r.prevos.net/antipodes/"> Data Science with R</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<div class="wp-caption"><img alt="The antipodes of each point on the Earth's surface" src="https://i2.wp.com/upload.wikimedia.org/wikipedia/commons/thumb/6/64/Antipodes_LAEA.png/481px-Antipodes_LAEA.png?resize=300%2C299&ssl=1" data-recalc-dims="1">
<p class="wp-caption-text">The antipode of each point on the Earth’s surface—the points where the blue and yellow overlap, are the land antipodes.</p>
</div>
<p>When I was a kid, I was was fascinated by the conundrum of what happens when you drill a hole straight through the centre of the earth. I always believed that I would turn up in Australia. But is this really the case?</p>
<p>The antipodes of any place on earth is the place that is diametrically opposite to it. A pair of antipodes are connected by a straight line running through the centre of the Earth. These points are as far away from each other as is possible on this planet. Two people are antipodes when they live on opposite sides of the globe. Their feet (πούς/pous in Ancient Greek) are directly opposite each other.</p>
<p>How can we use coding in R to solve this conundrum?</p>
<h2>Using R to find antipodes</h2>
<p><img sizes="(max-width: 300px) 100vw, 300px" alt="" class="wp-image-139" src="https://i2.wp.com/r.prevos.net/wp-content/uploads/sites/11/2017/01/antipodes-e1484823681907-300x289.png?resize=300%2C289" data-recalc-dims="1">We can roughly recreate the antipodean map on Wikipedia with the <a target="_blank" rel="nofollow" href="https://cran.r-project.org/web/packages/globe/"><em>globe</em> package</a>. This package, written by Adrian Baddeley, plots 2D and 3D views of the earth. The package contains a data file with major coastlines that can be used to create a flipped map of the world.</p>
<p>The package contains a data file with major coastlines that can be used to create a flipped map of the world. To turn a spatial location into its antipode you subtract 180 degrees from the longitude and reverse the sign of the latitude, shown below.</p>
<pre>
library(globe)
# Create antipodean map
flip &lt;- earth
flip$coords[,1] &lt;- flip$coords[,1]-180
flip$coords[,2] &lt;- -flip$coords[,2]
par(mar=rep(0,4)) # Remove plotting margins
globeearth(eye=c(90,0), col=&quot;blue&quot;)
globepoints(loc=flip$coords, eye=c(90,0), col=&quot;red&quot;, pch=&quot;.&quot;)
</pre>
<p>We can also use the<a target="_blank" rel="nofollow" href="https://cran.r-project.org/web/packages/ggmap/index.html"> ggmap package</a> to visualise antipodes. This package, developed by David Kahle antipodean R-guru Hadley Wickham, has a neat geocoding function to obtain a spatial location. The antipode function takes the description of a location and a zoom level to plot a dot on the antipode location. The gridExtra package is used to created a faceted map, which is not otherwise possible in ggmap.</p>
<pre>
library(ggmap)
library(gridExtra)

antipode &lt;- function(location, zm=6) {
    # Map location
    lonlat &lt;- geocode(location)
    loc1 &lt;- get_map(lonlat, zoom=zm)
    map1 &lt;- ggmap(loc1) + geom_point(data=lonlat, aes(lon, lat, col=&quot;red&quot;, size=10)) + 
        theme(legend.position=&quot;none&quot;)
    # Define antipode
    lonlat$lon &lt;- lonlat$lon-180
    lonlat$lat &lt;- -lonlat$lat
    loc2 &lt;- get_map(lonlat, zoom=zm)
    map2 &lt;- ggmap(loc2) + geom_point(data=lonlat, aes(lon, lat, col=&quot;red&quot;, size=10)) + 
        theme(legend.position=&quot;none&quot;)
    grid.arrange(map1, map2, nrow=1)
}

antipode(&quot;Rector Nelissenstraat 47 Hoensbroek&quot;, 4)
</pre>
<p>This code solves the problem I was thinking about as a child. Running the code shows that the antipodes location of the home I grew up in is not in Australia, but quite a way south of New Zealand. Another childhood fantasy shattered …</p>
<p>
<div class="wp-caption"><img sizes="(max-width: 582px) 100vw, 582px" alt="" class="wp-image-148" src="https://i2.wp.com/r.prevos.net/wp-content/uploads/sites/11/2017/01/antipodes-1.png?resize=456%2C241" data-recalc-dims="1">
<p class="wp-caption-text">Antipodes using ggmap and gridExtra.</p>
</div>
<p>The post <a target="_blank" rel="nofollow" href="http://r.prevos.net/antipodes/">Finding antipodes using the globe and ggmap packages</a> appeared first on <a target="_blank" rel="nofollow" href="http://r.prevos.net/">Data Science with R</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="http://r.prevos.net/antipodes/"> Data Science with R</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/g2eEP9-Esr8"></a></div>