Mapping Eurostat information Part 1

Keeping up with the theme of utilizing official government open data to map via an R package I will now turn to the eurostat package which accesses data - via an API - from the European Commission.

First released in 2015, there is an article (wuth R code) by its authors in the most recent issue of the R Journal,9/1 which makes for an interesting read covering a variety of topics

However, by it’s very nature, the article is static and - given the time-lag in publication (around 9 months) - neither uses the most recently available data nor takes advantage of the latest versions of packages or indeed the availability of new ones.

I have, therefore, adapted some of their code. There is quite a lot to take in, so this post just represents the first part of the analysis

As usual, libraries loaded are first

# data

# data carpentry

# interactive plots

# maps

Mapping Disposable income

An earlier post First look at tidycensus used packages which seamlessly downloaded shapefiles with data in the form of sf list-columns - although for practical purposes I kept geometries seperate and then merged to data, as required

The Eurostat package does not, currently, provide that functionality but a useful tip in the github issues from Joona Lehtomäki resolved this. The shapefile resolution obtained (1:10million) is sufficient for this example wothout looking crude but other levels are available

#Here we a combination of functions from the sf and eurostat packages to get spatial data 
res10 <- sf::st_as_sf(eurostat::get_eurostat_geospatial(output_class = "spdf", resolution = 10))

# load table which links regional codes from downloaded data to 
# Raw data NUTS_2013 from

# areaCodes <- read_csv("data/NUTS_2013.csv")
# areaCodes <- areaCodes %>% 
#   mutate(name=(str_replace(`NUTS LABEL`,"Arr. ",""))) %>% 
#   mutate(name=(str_replace(name,"Prov. ",""))) %>% 
#   rename(NUTS_ID=`NUTS CODE`)
# write_csv(areaCodes,"data/eurostatAreaCodes.csv")

areaCodes <- read_csv("data/eurostatAreaCodes.csv")

#The datasets now include a common field, NUTS_ID
## [1] "NUTS_ID"

We can view the available tables of content (9333 at time of writing) and then select the code required

toc <- get_eurostat_toc()

toc %>% 
                 DT::datatable(width="100%",class='compact stripe hover row-border order-column',rownames=FALSE,options= list(paging = TRUE, searching = TRUE,info=FALSE))