Get started with giscoR

Introduction

giscoR is a package designed to provide a clean interaction with the GISCO API.

Within Eurostat, GISCO is responsible for meeting the European Commission’s geographical information needs at 3 levels: the European Union, its member countries, and its regions. GISCO also provides a variety of shapefiles on different formats, focusing specially in the European Union area, but providing also some worldwide shapefiles, as country polygons, labels or borders and coastal lines.

GISCO provides data on different resolutions suitable for representing small areas (01M, 03M) as well as lightweight datasets specially useful for representing wider areas (10M, 20M, 60M). Shapefiles are provided on 3 different projections: EPSG 4326, 3035 or 3857.

giscoR returns sf objects, so the sf package is necessary.

Caching

giscoR provides a dataset caching capability, that could be set as:

options(gisco_cache_dir = "~/path/to/dir")

When this option is set, giscoR just load first the requested shapefile from the local directory, speeding up the loading process. If the file is not available locally, it would be downloaded to that directory so the next time you need the corresponding data it would be loaded from the local directory.

If you experience any problems on downloading, you can also manually download the file from the GISCO API website and stored it on your local directory.

Installation

Install giscoR from CRAN:

install.packages(“giscoR”)

Development version (Github):

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

Downloading data

Please be aware that downloading provisions apply when using GISCO data. There is a function, gisco_attributions that would guide you on this topic. It also provides attributions on several languages.

library(giscoR)
gisco_attributions(copyright = TRUE)
#> 
#>     COPYRIGHT NOTICE
#> 
#>     When data downloaded from this page
#>     <https://ec.europa.eu/eurostat/web/gisco/geodata/reference-data/administrative-units-statistical-units>
#>     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: (C) EuroGeographics for the administrative boundaries
#>     - FR: (C) EuroGeographics pour les limites administratives
#>     - DE: (C) EuroGeographics bezuglich 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.
#> 
#> 
#> [1] "© EuroGeographics for the administrative boundaries"

Basic example

Some examples on data downloads


library(sf)
#> Linking to GEOS 3.5.1, GDAL 2.2.2, PROJ 4.9.2

countries <- gisco_get_countries(region = "Asia")

plot(st_geometry(countries), axes = TRUE)
title(sub = gisco_attributions(copyright = "FALSE"), cex.sub = 0.7)

You can select specific countries by name (in any language), ISO 3 codes or Eurostat codes. The only restriction is that you can’t mix country names, ISO3 and Eurostat codes on one single call.

It is possible also to combine different shapefiles, just set resolution and epsg (and optionally year) to the same value:


africa_north <-
  gisco_get_countries(
    country = c("Argelia", "Morocco", "Egipto", "Tunisia", "Libia"),
    resolution = "20",
    epsg = "4326",
    year = "2016"
  )

# Coastal lines

coast <- gisco_get_coastallines(resolution = "20",
                                epsg = "4326",
                                year = "2016")

plot(
  st_geometry(africa_north),
  axes = TRUE,
  col = "grey30",
  border = "grey80"
)
plot(st_geometry(coast), lwd = 2, add = TRUE)
title(sub = gisco_attributions(), cex.sub = 0.7)

Plotting giscoR

This is an example on how giscoR can play nicely with some Eurostat data. For plotting purposes we would use the cartography package, however any package that handles sf objects (e.g. ggplot2, tmap, leaflet, etc. could be used).

Also colorspace and rcartocolor packages are recommended, as they provide great color palettes.



library(cartography)
library(colorspace)

# Northen Europe

neur <-
  gisco_countrycode[gisco_countrycode$un.regionsub.name == "Northern Europe", ]

iso3 <- neur[!is.na(neur$CNTR_CODE),]$ISO3_CODE

# Add some more countries

iso3 <-
  c(iso3, "POL", "DEU", "AUT", 
  "CZE", "BEL", "NLD", "LUX", 
  "SVK", "HUN", "ROU")

nuts2 <- gisco_get_nuts(
  year = "2016",
  epsg = "4326",
  resolution = "20",
  nuts_level = "2",
  country = iso3
)

#Borders
borders <- gisco_get_countries(
  epsg = "4326",
  year = "2016",
  resolution = "20",
  region = c("Europe", "Africa")
)

# Eurostat data - Purchase parity power
pps <- giscoR::tgs00026
pps <- pps[pps$time == 2016, ]

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

# Prepare mapping
br <-
  1000 * c(0,
           10,
           12.5,
           15,
           17.5,
           20,
           22.5,
           25,
           max(nuts2.sf$values, na.rm = TRUE) / 1000 + 1)

# Palette
pal <- sequential_hcl(
  n = (length(br) - 1),
  pal = "Inferno",
  alpha = 0.8
)


opar <- par(no.readonly = TRUE)
par(mar = c(2, 2, 2, 2))

# Basemap
plot(st_geometry(nuts2), col = "grey80")

# Surrounding countries
plot(
  st_geometry(borders),
  border = "black",
  lwd = 3,
  col = "grey80",
  add = TRUE
)

choroLayer(
  nuts2.sf,
  var = "values",
  border = "grey50",
  breaks = br,
  col = pal,
  legend.pos = "n",
  colNA = "grey80",
  add = TRUE
)
plot(st_geometry(borders),
     border = "black",
     col = NA,
     add = TRUE)

att <- gisco_attributions()

legendChoro(
  title.txt = NA,
  breaks = paste0(br / 1000, "K EUR"),
  col = pal,
  nodata.col = "grey80",
  frame = TRUE
)
layoutLayer(
  "Purchase Parity Power, NUTS 2 regions of selected countries (2016)",
  scale = FALSE,
  col = pal[3],
  sources = att
)

par(opar)