giscoR

CRAN status CRAN results R build status codecov Project Status: Active – The project has reached a stable, usable state and is being actively developed. DOI

giscoR is a API package that helps to retrieve data from Eurostat - GISCO (the Geographic Information System of the COmmission). It also provides some lightweight data sets ready to use without downloading.

GISCO (FAQ) is a geospatial open data repository including several data sets as countries, coastal lines, labels or NUTS levels. The data sets are usually provided at several resolution levels (60M/20M/10M/03M/01M) and in 3 different projections (4326/3035/3857).

Note that the package does not provide metadata on the downloaded files, the information is available on the API webpage.

Full site with examples and vignettes on https://dieghernan.github.io/giscoR/

Installation

Install giscoR from CRAN:

install.packages("giscoR")

You can install the developing version of giscoR with:

library(remotes)
install_github("dieghernan/giscoR")

Usage

This script highlights some features of giscoR:

library(giscoR)
library(sf)

# Different resolutions
DNK_res60 <- gisco_get_countries(resolution = "60", country = "DNK")
DNK_res20 <-
  gisco_get_countries(resolution = "20", country = "DNK")
DNK_res10 <-
  gisco_get_countries(resolution = "10", country = "DNK")
DNK_res03 <-
  gisco_get_countries(resolution = "03", country = "DNK")


# Plot tmap

library(tmap)

plot60 <- qtm(DNK_res60, fill = "tomato", main.title = "60M")
plot20 <- qtm(DNK_res20, fill = "tomato", main.title = "20M")
plot10 <- qtm(DNK_res10, fill = "tomato", main.title = "10M")
plot03 <- qtm(DNK_res03, fill = "tomato", main.title = "03M")

tmap_arrange(plot60, plot20, plot10, plot03)

# Labels and Lines available

labs <- gisco_get_countries(
  spatialtype = "LB",
  region = "Africa",
  epsg = "3857"
)

coast <- gisco_get_countries(
  spatialtype = "COASTL",
  epsg = "3857"
)


tm_shape(coast, bbox = labs) +
  tm_lines("deepskyblue4") +
  tm_shape(labs) +
  tm_dots(
    col = "springgreen4",
    border.col = "darkgoldenrod1",
    shape = 21,
    border.lwd = 1,
    size = 1
  )

Labels

An example of a labeled map using tmap:

ITA <- gisco_get_nuts(country = "Italy", nuts_level = 1)


tm_shape(ITA, point.per = "feature") +
  tm_polygons() +
  tm_text("NAME_LATN")

Thematic maps

An example of a thematic map plotted with the tmap package. The information is extracted via the eurostat package:

nuts3 <- gisco_get_nuts(
  year = "2016",
  epsg = "3035",
  resolution = "3",
  nuts_level = "3"
)

# Countries
countries <-
  gisco_get_countries(
    year = "2016",
    epsg = "3035",
    resolution = "3"
  )

# Use eurostat
library(eurostat)

popdens <- get_eurostat("demo_r_d3dens")
popdens <- popdens[popdens$time == "2018-01-01", ]



nuts3.sf <- merge(nuts3,
  popdens,
  by.x = "NUTS_ID",
  by.y = "geo",
  all.x = TRUE
)

br <- c(0, 25, 50, 100, 200, 500, 1000, 2500, 5000, 10000, 30000)

# Plot
tm_shape(countries, bbox = c(23, 14, 74, 55) * 10e4) +
  tm_fill("#E0E0E0") +
  tm_shape(nuts3.sf) +
  tm_fill(
    "values",
    breaks = br,
    palette = "-inferno",
    alpha = .7,
    title = "Population density (km2)\nNUTS3 (2018)"
  ) +
  tm_shape(countries) +
  tm_borders(lwd = .25) +
  tm_credits(gisco_attributions(),
    position = c("left", "bottom")
  ) +
  tm_layout(
    bg.color = "#daf3ff",
    outer.bg.color = "white",
    legend.bg.color = "white",
    legend.frame = "black",
    legend.title.size = 0.8,
    inner.margins = c(0, 0, 0, 0),
    outer.margins = c(0, 0, 0, 0),
    frame = TRUE,
    frame.lwd = 0,
    attr.outside = TRUE
  )

A note on caching

Some data sets (as Local Administrative Units - LAU, or high-resolution files) may have a size larger than 50MB. You can use giscoR to create your own local repository at a given local directory passing the following option:

options(gisco_cache_dir = "./path/to/location")

When this option is set, giscoR would look for the cached file and it will load it, speeding up the process.

You can also download manually the files (.geojson format) and store them on your local directory.

API data packages

Plotting sf objects

Some packages recommended for visualization are:

Contribute

Check the Github page for source code.

Contributions are very welcome:

From GISCO > Geodata > Reference data > Administrative Units / Statistical Units

When data downloaded from this page is used in any printed or electronic publication, in addition to any other provisions applicable to the whole Eurostat website, data source will have to be acknowledged in the legend of the map and in the introductory page of the publication with the following copyright notice:

EN: © EuroGeographics for the administrative boundaries

FR: © EuroGeographics pour les limites administratives

DE: © EuroGeographics bezüglich der Verwaltungsgrenzen

For publications in languages other than English, French or German, the translation of the copyright notice in the language of the publication shall be used.

If you intend to use the data commercially, please contact EuroGeographics for information regarding their licence agreements.

Disclaimer

This package is in no way officially related to or endorsed by Eurostat.