<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/flat-earth-mathematics-in-the-r-language/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://lucidmanager.org/flat-earth-mathematics/"> The Devil is in the Data – The Lucid Manager</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>I am soon embarking on a trip around the world to speak at the <a rel="nofollow" href="http://worldwatercongress.org/" target="_blank">World Water Congress</a> in Tokyo, visit family and friends in the Netherlands and some tourism in San Francisco. One of the workshops I am involved with is about Fake News in the water industry.</p>
<p>Fake news and conspiracies are threatening western civilisation, and one of the craziest trends is the flat earth conspiracy. Some of you might ask whether my trip actually <em>around</em> the world or am I travelling across a <em>flat disk</em>?</p>
<p>This article discusses flat earth mathematics, and how to convert and visualise map projections in R. This article uses the code I published earlier in articles about <a rel="nofollow" href="https://lucidmanager.org/pacific-island-hopping/" target="_blank">creating flight maps</a> and <a rel="nofollow" href="https://lucidmanager.org/pacific-island-hopping/" target="_blank">Pacific island hopping</a>. You can view the code below or download the full version from <a rel="nofollow" href="https://github.com/pprevos/r.prevos.net/blob/master/Geography/flatearth.R" target="_blank">GitHub</a>.</p>
<h2>The Flat Earth</h2>
<p>YouTube contains thousands of videos from people that claim the earth is flat and that science as we know it is a “globalist conspiracy”. While their claims are hilarious, people that believe our planet is flat are often passionate and even conduct simple experiments and engage in naive flat earth mathematics.</p>
<p>Adherents to the idea that the world is flat often propose <a rel="nofollow" href="https://amzn.to/2Pxh3I7" target="_blank">Gleason’s Map</a> (shown above) as their version of the correct representation of our planet. This map is not a map of the flat earth but a polar <a rel="nofollow" href="https://en.wikipedia.org/wiki/Azimuthal_equidistant_projection" target="_blank">Azimuthal equidistant projection</a> of the globe. Even though the map itself states that it is a projection of the world, flat earth believers nevertheless see it as a literal representation of the earth.</p>
<p>Projecting the spherical earth on a flat surface is a complex task which will always require compromise as it is impossible to draw the surface of the globe on a piece of paper truthfully.Â  The video below provides a practical introduction to map projections.</p>
<p><iframe allowfullscreen="true" src="https://www.youtube.com/embed/kIID5FDi2JQ?version=3&rel=1&%23038;fs=1&%23038;autohide=2&%23038;showsearch=0&%23038;showinfo=1&%23038;iv_load_policy=1&%23038;wmode=transparent" width="450" type="text/html"></iframe></p>
<p>We can recreate Gleason’s map with <a rel="nofollow" href="https://ggplot2.tidyverse.org/reference/coord_map.html" target="_blank">ggplot</a>, which incorporates the <a rel="nofollow" href="https://cran.r-project.org/web/packages/mapproj/index.html" target="_blank">mapproj package</a> to show maps in various projections. The Azimuthal equidistant method is popularised in the flag of the United Nations. Antarctica is in this projection displayed as a ring around the world. Flat earth evangelists believe that the South Pole a ring of ice that prevents us from proceeding beyond the disc.</p>
<pre>
library(tidyverse)
library(tidyverse)
world &lt;- map_data(&quot;world&quot;)
worldmap &lt;- ggplot(world) +
    geom_path(aes(x = long, y = lat, group = group)) +
    theme(axis.text = element_blank(),
          axis.ticks = element_blank()) +
    labs(x = &quot;&quot;, y = &quot;&quot;)
worldmap + 
    coord_map(&quot;azequidistant&quot;, orientation = c(90, 0, 270))
</pre>
<p>The <a rel="nofollow" href="https://ggplot2.tidyverse.org/reference/coord_map.html" target="_blank">coord_map</a> function allows you to change projections. The orientation argument defines the centre point of the projection. The most common location is the North Pole (90, 0). The third value gives the clockwise rotation in degrees. Gleason’s map uses a rotation of 270 degrees.</p>
<h2>My Round-the-World Itinerary</h2>
<p>My trip will take me from Australia to Japan, from where I go to the Netherlands. The last two legs will bring me back to Australia via San Francisco.</p>
<p>The itinerary is stored in a data frame, and the ggmap package geocodes the longitude and latitude of each of the locations on my trip. As the earth is a sphere, an intermediate point needs to be added for trips that pass the dateline, as I explained in my article about <a rel="nofollow" href="https://lucidmanager.org/create-air-travel-route-maps/" target="_blank">flight maps</a>.</p>
<p>The itinerary is visualised using the same method as above but centring on Antarctica. The geosphere package helps to estimate the total travel distance, which is approximately 38,995 km, slightly less than a trip around the equator. This distance is the <a rel="nofollow" href="https://en.wikipedia.org/wiki/Great-circle_distance" target="_blank">great circle distance</a>, which is the shortest distance between two points on a sphere, adjusted for a spheroid (a flattened sphere).</p>
<p>The flight paths on this map are curved because of the inevitable distortions when projecting a sphere on a flat surface.</p>
<pre>
## Define itinerary
library(ggmap)
airports &lt;- tibble(city = c(&quot;Melbourne&quot;, &quot;Tokyo&quot;, &quot;Amsterdam&quot;, &quot;San Francisco&quot;, &quot;Melbourne&quot;))

## Find coordinates
## Where you receive an OVER_QUERY_LIMIT error, repeat the code
itinerary &lt;- geocode(airports$city) %>%
    mutate(location = airports$city)

## Split travel past dateline
dl &lt;- which(diff(itinerary$lon) > 180)
dr &lt;- ifelse(itinerary$lon[dl] &lt; 0, -180, 180)
dateline &lt;- tibble(lon = c(dr, -dr),
                   lat = rep(mean(itinerary$lat[dl:(dl + 1)]), 2),
                   location = &quot;dateline&quot;)
itinerary &lt;- rbind(itinerary[1:dl, ], dateline, itinerary[(dl + 1):nrow(itinerary), ]) itinerary ## Visualise worldmap + geom_point(data = itinerary, aes(lon, lat), colour = &quot;red&quot;, size = 4) + geom_path(data = itinerary, aes(lon, lat), colour = &quot;red&quot;, size = 1) + coord_map(&quot;azequidistant&quot;, orientation = c(-90, 0, 270)) ggsave(&quot;rtw.png&quot;, dpi = 150) ## Great Circle Distance library(geosphere) sapply(1:(nrow(itinerary) - 1), function(l) distVincentyEllipsoid(itinerary[l, 1:2], itinerary[(l + 1), 1:2]) / 1000) %>%
    sum()
</pre>
<figure class="wp-caption"><a rel="nofollow" href="https://lucidmanager.org/flat-earth-mathematics/rtw/" target="_blank"><img data-orig-file="https://i1.wp.com/lucidmanager.org/wp-content/uploads/sites/2/2018/09/rtw.png?fit=1048%2C1048&amp;ssl=1" data-orig-size="1048,1048" data-medium-file="https://i1.wp.com/lucidmanager.org/wp-content/uploads/sites/2/2018/09/rtw.png?fit=300%2C300&amp;ssl=1" data-attachment-id="6238" data-image-meta="{" data-image-description="" src="https://i1.wp.com/lucidmanager.org/wp-content/uploads/sites/2/2018/09/rtw.png?resize=525%2C525&ssl=1" data-permalink="https://lucidmanager.org/flat-earth-mathematics/rtw/" data-large-file="https://i1.wp.com/lucidmanager.org/wp-content/uploads/sites/2/2018/09/rtw.png?fit=525%2C525&amp;ssl=1" alt="Rount the world trip" data-image-title="rtw" sizes="(max-width: 525px) 100vw, 525px" width="450" data-comments-opened="1" class="wp-image-6238" data-recalc-dims="1"></a><figcaption class="wp-caption-text">Round the world trip in polar Azimuthal equidistant projection.</figcaption></figure>
<h2>Flat Earth Mathematics</h2>
<p>If the Gleason map were in reality a map of the flat earth, then the flight paths on the map would show as straight lines. I was unable to plot these lines on the map because ggplot corrects for the projection effects.</p>
<p>The mapproj package contains the mapproject function to calculate the projected coordinates based on longitude and latitude. The output of this function is a grid with limits from <img alt="-pi" title="-pi" src="https://s0.wp.com/latex.php?latex=-%5Cpi&bg=ffffff&%23038;fg=000&%23038;s=0" class="latex"> to <img alt="pi" title="pi" src="https://s0.wp.com/latex.php?latex=%5Cpi&bg=ffffff&%23038;fg=000&%23038;s=0" class="latex">.</p>
<p>On the polar Azimuthal equidistant projection, distances from any point to the centre of the map are not distorted. A line from the lon/lat 0,0 to the north pole has a projected distance on <img alt="pi/2" title="pi/2" src="https://s0.wp.com/latex.php?latex=%5Cpi%2F2&bg=ffffff&%23038;fg=000&%23038;s=0" class="latex">, which in the spherical world is <img alt="pi / 2 * 6378.137Â  = 10018.75" title="pi / 2 * 6378.137Â  = 10018.75" src="https://s0.wp.com/latex.php?latex=%5Cpi+%2F+2+%2A+6378.137%C2%A0+%3D+10018.75&bg=ffffff&%23038;fg=000&%23038;s=0" class="latex"> km. In other words, we need to multiply the Euclidean distance with the radius of the Earth to estimate the length on a flat map.</p>
<p>This last code snippet converts the itinerary to projected coordinates, calculates the Euclidean distance between the points and multiplies this with the Earth’s diameter. The outcome is a staggering 83,675 km, more than twice the length over a sphere. The main reason for this difference is the distortion of this projection. When taking Antartica as the centre of the projection, East-West lengths on the Northern hemisphere are massively distorted. When undertaking the same calculation with the North pole as the center, the total distance is 46,348 km, still a lot more than the actual length of the journey. The only leg with a similar distance to reality is from Brisbane to Tokyo because this route is almost a radial line without distortion.</p>
<p>This article proves that the earth cannot be flat because aeroplanes would have to break the sound barrier to fly these distances in the time it takes to travel. But these facts will not stop people believing in a flat earth, I am after all an engineer and thus part of the globalist science conspiracy.</p>
<p>You can view the complete code on my <a rel="nofollow" href="https://github.com/pprevos/r.prevos.net/blob/master/Geography/flatearth.R" target="_blank">GitHub</a> repository.</p>
<pre>
library(mapproj)
coords &lt;- mapproject(itinerary$lon, itinerary$lat, &quot;azequidistant&quot;,
                     orientation = c(-90, 0, 270))
coords &lt;- tibble(x = coords$x, y = coords$y)
sum(sqrt(diff(coords$x)^2 + diff(coords$y)^2) * 6378.137)
</pre>
<p>The post <a rel="nofollow" href="https://lucidmanager.org/flat-earth-mathematics/" target="_blank">Flat Earth Mathematics in the R Language</a> appeared first on <a rel="nofollow" href="https://lucidmanager.org/" target="_blank">The Lucid Manager</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://lucidmanager.org/flat-earth-mathematics/"> The Devil is in the Data – The Lucid Manager</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/5Wa3yaCCleY" height="1"></a></div>