knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

unlocodeR

Lifecycle: experimental CRAN status

The goal of unlocodeR is to provide access for the UN Code for Trade and Transport Locations for geospatial standardization as well as associated tables for translating codes. This is an excellent classification that gets at lower level geographic entities that states or provinces - such as cities, railroad stations, airports, and more. See http://www.unece.org/cefact/codesfortrade/codes_index.html/ for much more detail about the standard, as well as the docs here.

Installation

<!-- You can install the released version of unlocodeR from CRAN with:

install.packages("unlocodeR")

-->

remotes::install_github("jebyrnes/unlocodeR")

The Data

library(unlocodeR)

head(unlocode)

Coverage

While some of the lat/longs are NA and some might be a hair off due to manual correction of bad entries, spatial coverage is fairly good.

library(unlocodeR)
library(sf)
library(dplyr)
library(ggplot2)
library(rnaturalearth)

unsf <- unlocode %>%
  filter(!is.na(latitude_dec)) %>%
  filter(latitude_dec < 180,
         abs(longitude_dec) < 180) %>%
  st_as_sf(coords = c("longitude_dec", "latitude_dec"), crs=4326)

ggplot() +
  geom_sf(data = ne_countries(returnclass = "sf")) +
  geom_sf(data = unsf) +
  theme_void()

Here it is for the US, for example

uslocode <- unlocode %>%
  filter(iso_3166_2_country=="US")


ggplot() +
  geom_sf(data = ne_countries(returnclass = "sf")) +
  geom_point(data = uslocode, aes(x = longitude_dec, y = latitude_dec)) +
  theme_void()


jebyrnes/unlocodeR documentation built on May 18, 2020, 12:57 p.m.