README.md

CRAN
status Project Status: Active – The project has reached a stable, usable
state and is being actively
developed. R-CMD-check

rnaturalearth

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

This package provides :

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

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)
The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
which was just loaded, will retire in October 2023.
Please refer to R-spatial evolution reports for details, especially
https://r-spatial.org/r/2023/05/15/evolution4.html.
It may be desirable to make the sf package available;
package maintainers should consider adding sf to Suggests:.
The sp package is now running under evolution status 2
     (status 2 uses the sf package in place of rgdal)
Support for Spatial objects (`sp`) will be deprecated in {rnaturalearth} and will be removed in a future release of the package. Please use `sf` objects with {rnaturalearth}. For example: `ne_download(returnclass = 'sf')`
library(sp)

# world countries
sp::plot(ne_countries())
Warning: The `returnclass` argument of `ne_download()` sp as of rnaturalearth 1.0.0.
ℹ Please use `sf` objects with {rnaturalearth}, support for Spatial objects
  (sp) will be removed in a future release of the package.
This warning is displayed once every 8 hours.
Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
generated.

# 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



Try the rnaturalearth package in your browser

Any scripts or data that you put into this service are public.

rnaturalearth documentation built on Aug. 21, 2023, 5:12 p.m.