<h2>Map of Middle Earth</h2><div><a href="https://1.bp.blogspot.com/-85YO4d4YRQw/V_mL3ybVORI/AAAAAAAAAyE/O4-wO0Kvmig7mkOShlUbD5PxbENs4O28ACLcB/s1600/middle_earth.png"></a></div>The map above was created using ggplot2, ggmaps, and maptools in R.  These are just a few of the great R packages available for cartography and geographic applications.  Many readers of this blog will be familiar with these packages and more recent R package additions like <a href="https://rstudio.github.io/leaflet/">leaflet</a>.  But great packages are only part of the problem... geographic data about Middle earth is generally found on the inside cover of Tolkien books or perhaps in the <a href="https://www.amazon.com/Atlas-Middle-Earth-Revised-Karen-Fonstad/dp/0618126996?tag=rcha-20">Atlas of Middle Earth</a>.  And this &quot;data&quot; is just pictures.<br><br>Fortunately shapefiles are available in a Github Repo that represent many of the significant features of middle earth:  https://github.com/jvangeld/ME-GIS.  Thanks to the creators of these files (<a href="http://worlds.outercraft.com/forum/">the Middle Earth DEM Project</a>) for your work and generously making these files available online. <br><br>If you want to follow along with the R code that follows, clone this repo or download the files to your local machine and extract 'em.<br><br>Creating the map above is straightforward... load the required R packages:<br><br><span>library(ggplot2)</span><br><span>library(ggmap)</span><br><span>library(maptools)</span><br><br>The ggplot2 package is used to plot the map.  The ggmap package includes the <span>fortify()</span> function which translates the shapefile data into a data frame and the maptools package is used to read the shape files.<br><br>Next, navigate to the directory containing the shapefiles and read in the data<br><br><span>setwd('/path/to/downloaded/ME-GIS/')</span><br><br>Read in the data files using maptools.<br><br><span>coastline -></span><br><span>forests -></span><br><span>lakes -></span><br><span>rivers -></span><br><span>contours -></span><br><br>Render the map.  Each of the variables containing data is associated with a geom_polygon or geom_path function call.<br><br><span>ggplot() +</span><br><span> geom_polygon(data = fortify(contours), </span><br><span>              aes(x = long, y = lat, group = group),</span><br><span>              color = '#f0f0f0', fill='#f0f0f0', size = .2) +</span><br><span> geom_path(data = fortify(coastline), </span><br><span>           aes(x = long, y = lat, group = group),</span><br><span>           color = 'black', size = .2) +</span><br><span> geom_polygon(data = fortify(forests), </span><br><span>          aes(x = long, y = lat, group = group),</span><br><span>          color = '#31a354', fill='#31a354', size = .2) +</span><br><span> geom_polygon(data = fortify(lakes), </span><br><span>            aes(x = long, y = lat, group = group),</span><br><span>            color = '#a6bddb', fill='#a6bddb', size = .2) +</span><br><span> geom_path(data = fortify(rivers), </span><br><span>            aes(x = long, y = lat, group = group),</span><br><span>            color = '#a6bddb', size = .2) + </span><br><span> ggtitle('Middle Earth') + </span><br><span> ylab('') + </span><br><span> xlab('Shapefiles: https://github.com/jvangeld/ME-GIS')</span><br><br>So if you looking for a brief escape into a fantasy realm or hoping to inspire young imaginative cartographers, check out the data at github, load the shapefiles into R using maptools or the rgdal package and get plotting!<br><br>