Goal: visualize first instance decisions on applications by citizenship, age and sex annual aggregated data from Eurostat.

  1. Load libraries:
library(eurostat)
library(data.table)
library(tidyr)
library(magrittr)
library(plyr)
library(dplyr)
library(rjson)
library(viridisLite)
library(highcharter)
  1. Download the data:
if(!file.exists("data_asylum.Rdata")){
  data <- "migr_asydcfsta" %>% get_eurostat %>% data.table
  save(data, file="data_asylum.Rdata")
}
load("data_asylum.Rdata")
dic <- lapply(names(data), get_eurostat_dic)
eumap <- rjson::fromJSON(file = "http://code.highcharts.com/mapdata/custom/europe.geo.json", method = 'C')
for (i in 1:length(eumap$features))
{
  names(eumap$features[[i]][[3]])[names(eumap$features[[i]][[3]]) %in% "iso-a2"] <- "code"
}
data[, period := year(time)]
data[, time := NULL]

data <- data[age %in% "TOTAL" & decision %in% c("TOTAL", "REJECTED") & citizen %in% "TOTAL" & sex %in% "T", ]
data[, geo1 := as.character(geo)]
data[, geo := NULL]
setnames(data, "geo1", "geo")
data[, c("age", "citizen", "sex") := NULL]
setnames(data, "geo", "code")
setnames(data, "values", "value")
data <- data[!code %in% c("EU28", "TOTAL")]
data[code %in% "UK", code := "GB"]
data[code %in% "EL", code := "GR"]
datl <- c()
coll <- c()
coll1 <- c()
yyl <- 2017
for (yy in yyl)
{
  dat <- data[period == yy]
  dat <- tidyr::spread(dat, decision, value)
  setnames(dat, "TOTAL", "value")
  dat <- dat[!is.na(value)]
  dat[, prc := round(REJECTED / value * 100, 1)]
  
  sum <- summary(dat[, value])
  sum1 <- summary(dat[, prc])
  
  dclass <- data_frame(from = sum[-6],
                       to = sum[-1],
                       color = substring(viridis(length(from), option = "C"), 0, 7))
  dclass <- list.parse3(dclass)
  dat <- tbl_df(dat)
  dclass1 <- data_frame(from = sum1[-6],
                        to = sum1[-1],
                        color = substring(viridis(length(from), option = "C"), 0, 7))
  dclass1 <- list.parse3(dclass1)
  datl <- c(datl, list(dat))
  coll <- c(coll, list(dclass))
  coll1 <- c(coll1, list(dclass1))
}  
hcl[[1]]
hcl1[[1]]
## Registered S3 method overwritten by 'xts':
##   method     from
##   as.zoo.xts zoo
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo

Source: Eurostat.

Dataset: First instance decisions on applications by citizenship, age and sex Annual aggregated data (rounded) (migr_asydcfsta).

Metadata: Meta.