Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Map of Middle Earth

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 leaflet.  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 Atlas of Middle Earth.  And this "data" is just pictures.

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 (the Middle Earth DEM Project) for your work and generously making these files available online.

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.

Creating the map above is straightforward... load the required R packages:

library(ggplot2)
library(ggmap)
library(maptools)

The ggplot2 package is used to plot the map.  The ggmap package includes the fortify() function which translates the shapefile data into a data frame and the maptools package is used to read the shape files.

Next, navigate to the directory containing the shapefiles and read in the data

setwd('/path/to/downloaded/ME-GIS/')

Read in the data files using maptools.


coastline = readShapeSpatial('Coastline2.shp')
forests = readShapeSpatial('Forests.shp')
lakes = readShapeSpatial('Lakes2.shp')
rivers = readShapeSpatial('Rivers19.shp')
contours = readShapeSpatial('Contours_18.shp')

Render the map.  Each of the variables containing data is associated with a geom_polygon or geom_path function call.

ggplot() +
 geom_polygon(data = fortify(contours), 
              aes(x = long, y = lat, group = group),
              color = '#f0f0f0', fill='#f0f0f0', size = .2) +
 geom_path(data = fortify(coastline), 
           aes(x = long, y = lat, group = group),
           color = 'black', size = .2) +
 geom_polygon(data = fortify(forests), 
          aes(x = long, y = lat, group = group),
          color = '#31a354', fill='#31a354', size = .2) +
 geom_polygon(data = fortify(lakes), 
            aes(x = long, y = lat, group = group),
            color = '#a6bddb', fill='#a6bddb', size = .2) +
 geom_path(data = fortify(rivers), 
            aes(x = long, y = lat, group = group),
            color = '#a6bddb', size = .2) + 
 ggtitle('Middle Earth') + 
 ylab('') + 
 xlab('Shapefiles: https://github.com/jvangeld/ME-GIS')

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!



This post first appeared on R-Chart, please read the originial post: here

Share the post

Map of Middle Earth

×

Subscribe to R-chart

Get updates delivered right to your inbox!

Thank you for your subscription

×