🌍 an R package to hold and facilitate interaction with natural earth map data
R

README.md

Travis-CI Build Status

Build status

rnaturalearth

An R package to hold and facilitate interaction with Natural Earth map data.

Aims :

  1. access to a pre-downloaded subset of Natural Earth vectors commonly used in world mapping
  2. allow easy subsetting by countries and regions
  3. facilitate download of other Natural Earth vectors
  4. provide a simple, reproducible and sustainable workflow from Natural Earth data to rnaturalearth enabling updating as new versions become available
  5. to clarify differences in world maps classified by countries, sovereign states and map units
  6. to follow Natural Earth naming conventions so that rnaturalearth users can use Natural Earth documentation

The Natural Earth website structures vector data by scale, category and type. These determine the filenames of downloads. rnaturalearth uses this structure to facilitate download (like an API).

Install rnaturalearth

You can install the development version from GitHub using devtools.

devtools::install_github("ropenscilabs/rnaturalearth")

Data to support much of the package functionality are stored in a data package that you will be prompted to install when required if you do not do so here.

devtools::install_github("ropenscilabs/rnaturalearthdata")

First Usage

Here using sp::plot as a simple, quick way to plot maps. Maps could also be made with ggplot2, tmap or other options.

library(rnaturalearth)
library(sp)

#world countries
sp::plot(ne_countries())

#uk
sp::plot(ne_countries(country = 'united kingdom'))

#states, admin level1 boundaries
sp::plot(ne_states(country = 'spain')) 

Introductory vignette

vignette('rnaturalearth', package='rnaturalearth')

To download Natural Earth data not already in the package

Specify the scale, category and type of the vector you want. For example for scale = 50 and category = 'physical' the available options for type can be found here. Examples :

#lakes
lakes110 <- ne_download(scale = 110, type = 'lakes', category = 'physical')
plot(lakes110)

#rivers
rivers50 <- ne_download(scale = 50, type = 'rivers_lake_centerlines', category = 'physical')
plot(rivers50)

Details of different country definitions and scales

vignette('what-is-a-country', package='rnaturalearth')

Reproducible download of Natural Earth data into the package

Script used to get data into the accompanying data packages.

Acknowledgements

Thanks to Lincoln Mullen for code structure inspiration from USAboundaries, Hadley Wickham for comments and prompting, Bob Rudis for answers to stackoverflow questions about downloading Natural Earth data into R. The Natural Earth team and Nathan Kelso for providing such a great resource.

Potential future work

potential additional data

  1. Country synonyms lookup

  2. Country larger regions lookup

potential additional functions

  1. facilitate joining of user data to country boundaries

  2. facilitate subsetting by country groupings

    • e.g. least developed countries etc.

ropensci\_footer