Learn R Programming

⚠️There's a newer version (1.0.1) of this package.Take me there.

rnaturalearth

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

This package provides :

  • access to a pre-downloaded subset of Natural Earth v4.1.0 (March 2018) vector data commonly used in world mapping

  • easy subsetting by countries and regions

  • functions to download other Natural Earth vector and raster data

  • a simple, reproducible and sustainable workflow from Natural Earth data to rnaturalearth enabling updating as new versions become available

  • clarification of differences in world maps classified by countries, sovereign states and map units

  • consistency with Natural Earth naming conventions so that rnaturalearth users can use Natural Earth documentation

  • data in ‘sf’ or ‘sp’ formats

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).

s## Install rnaturalearth

Install from CRAN :

install.packages("rnaturalearth")

or install the development version from GitHub using devtools.

devtools::install_github("ropensci/rnaturalearth")

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

devtools::install_github("ropensci/rnaturalearthdata")
devtools::install_github("ropensci/rnaturalearthhires")

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. All retrieval functions accept an argument returnclass='sf' to return package sf (Simple Features) objects.

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

There are a wealth of other data available at the Natural Earth website. rnaturalearth has functions to help with download of these data.

The data available are outlined in the two tables below and online here.

category   cultural 

category   physical 

Specify the scale, category and type of the vector you want as in the examples below.

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

# rivers
rivers50 <- ne_download(
  scale = 50,
  type = "rivers_lake_centerlines",
  category = "physical",
  returnclass = "sf"
)

library(ggplot2)
library(sf)

ggplot(rivers50) +
  geom_sf() +
  theme_minimal()

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

Potential additional functions

  • facilitate joining of user data to country boundaries
  • facilitate subsetting by country groupings
    • e.g. least developed countries etc.

Copy Link

Version

Install

install.packages('rnaturalearth')

Monthly Downloads

25,277

Version

0.3.2

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Last Published

January 23rd, 2023

Functions in rnaturalearth (0.3.2)

ne_as_sp

coerce return object to sp if option set
ne_coastline

Get natural earth world coastline
ne_states

Get natural earth world state (admin level 1) polygons
ne_load

load a Natural Earth vector that has already been downloaded to R using ne_download
ne_find_vector_data

Return a dataframe of available vector layers on Natural Earth
ne_file_name

return a natural earth filename based on arguments
ne_countries

Get natural earth world country polygons
ne_download

download data from Natural Earth and (optionally) read into R
rnaturalearth

rnaturalearth : world map data from Natural Earth
ne_git_layer_names

Create list of layer names and metadata links
ne_git_contents

Return contents of Natural Earth Github directory
check_rnaturalearthdata

Check whether to install rnaturalearthdata and install if necessary
install_rnaturalearthhires

Install the naturalearthhires package after checking with the user
get_data

Get data from within the package
countries

world country polygons from Natural Earth
install_rnaturalearthdata

Install the naturalearthdata package after checking with the user
check_scale

check that this scale is present in Natural Earth
check_data_exist

check whether the requested data exist on Natural Earth
check_rnaturalearthhires

Check whether to install rnaturalearthhires and install if necessary
df_layers_physical

list of physical layers available from Natural Earth
df_layers_cultural

list of cultural layers available from Natural Earth