Prerequisite

The data have been analysed with R (version 4.1.0) and Rstudio (version 1.4.1717), and the website has been created with bookdown package and GitHub.

There are some comflicts between ggtern (3.3.0) and ggplot2 (3.3.5), and some ggplots do not work after calling ggtern. I have used therefore renv for controlling the package versions in the project. In this sense, we can work in a separate project where we can plot ternary plots with ggternor tricolore using a previous version of ggplot2 (i.e. 3.3.0). You may also need to install other packages.

# # Initialize a new project-local environment
# renv::init()
# 
# # Install Packages (uncomment as you need)
# install.packages("sf")
# install.packages("ggspatial")
# install.packages("ggtern")
# install.packages("tricolore")
# install.packages("danstat")
# install.packages("furrr")
# install.packages("SnowballC")
# install.packages("patchwork")
# install.packages("tm")
# install.packages("data.table")
# install.packages("tidytable")
# install.packages("latex2exp")
# install.packages("rmarkdown")
# install.packages("bookdown")
# install.packages("servr")
# install.packages("devtools")
# devtools::install_version("tidyverse",
#                           version = "1.3.0",
#                           repos = "http://cran.us.r-project.org")
# devtools::install_version("ggplot2",
#                           version = "3.3.0",
#                           repos = "http://cran.us.r-project.org")

# List of packages
my_pkgs <- c("sf", "ggspatial", "ggtern", "tricolore", "tidyverse", "danstat",
             "furrr", "SnowballC", "patchwork", "tm", "data.table", "tidytable",
             "latex2exp", "rmarkdown")

# Load packages
lapply(my_pkgs, require, character.only = TRUE)

# # Save the state of the project
# renv::snapshot()

Furthermore, we have created our own package for downloading kortforsyningen data to a local repository directly from R (i.e. dangeo). The package can be downloaded from GitHub:

# Install packages from GitHub
  if(!require("devtools"))  install.packages("devtools")

  if (!require("dangeo"))  remotes::install_github("javiereliomedina/dangeo")
  library(dangeo)

Although the kortforsyningen data are free, we would need to create a username and a password for getting access to them (you can make it here: “Opret ny bruger”). By default dangeo looks for credentials on .Renviron as: kortforsyningen_id = "username" and kortforsyningen_pwd = "password". You would need to save them with usethis::edit_r_environ():

# Set username and password 
# usethis::edit_r_environ() # Open .Renviron file, and save the username (kortforsyningen_id = "your_username") and password (kortforsyningen_pwd = "your_password")

You would also need to define with dangeo_set_param() the local directory where the data are downloaded (loc_dir). It is defined as loc_dir = rappdirs::user_cache_dir(), although it can be changed loc_dir = “./your/local/path”. The first time a file is downloaded with dangeo_get_data(), the process can be time consuming (there are some very big files). However, it will not be downloaded in subsequent calls if the files is already in the local directory (the dataset can be overwritten be setting overwrite = TRUE on dangeo_get_data()). Once we have our username and password, and we have define the local repository for the data, we can set them on our R-session:

# Set local repository and password to kortforsyningen
  dangeo_set_param()

Acknowledgements

This work has been financed by Aalborg University - AAU (Project: Global flows of migrants and their impact on north European welfare states - FLOW). The sole responsibility of this publication lies with the authors. AAU is not responsible for any use that may be made of the information contained therein.

R session

# R version 4.1.0 (2021-05-18)
# Platform: x86_64-w64-mingw32/x64 (64-bit)
# Running under: Windows 10 x64 (build 19042)
# 
# Matrix products: default
# 
# locale:
# [1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252   
# [3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           
# [5] LC_TIME=English_United Kingdom.1252    
# 
# attached base packages:
# [1] stats     graphics  grDevices datasets  utils     methods   base     
# 
# other attached packages:
#  [1] dangeo_0.0.0.9000 devtools_2.4.2    usethis_2.0.1     rmarkdown_2.9    
#  [5] latex2exp_0.5.0   tidytable_0.6.3   data.table_1.14.0 tm_0.7-8         
#  [9] NLP_0.2-1         patchwork_1.1.1   SnowballC_0.7.0   furrr_0.2.3      
# [13] future_1.21.0     danstat_0.1.0     forcats_0.5.1     stringr_1.4.0    
# [17] dplyr_1.0.7       purrr_0.3.4       readr_2.0.0       tidyr_1.1.3      
# [21] tibble_3.1.2      tidyverse_1.3.0   tricolore_1.2.2   ggtern_3.3.0     
# [25] ggplot2_3.3.0     ggspatial_1.1.5   sf_1.0-1         
# 
# loaded via a namespace (and not attached):
#  [1] colorspace_2.0-2   ellipsis_0.3.2     class_7.3-19       rprojroot_2.0.2   
#  [5] fs_1.5.0           rstudioapi_0.13    proxy_0.4-26       listenv_0.8.0     
#  [9] remotes_2.4.0      fansi_0.5.0        lubridate_1.7.10   xml2_1.3.2        
# [13] codetools_0.2-18   cachem_1.0.5       robustbase_0.93-8  knitr_1.33        
# [17] pkgload_1.2.1      jsonlite_1.7.2     broom_0.7.8        dbplyr_2.1.1      
# [21] compiler_4.1.0     httr_1.4.2         backports_1.2.1    assertthat_0.2.1  
# [25] fastmap_1.1.0      cli_3.0.1          prettyunits_1.1.1  htmltools_0.5.1.1 
# [29] tools_4.1.0        gtable_0.3.0       glue_1.4.2         rappdirs_0.3.3    
# [33] Rcpp_1.0.7         slam_0.1-48        cellranger_1.1.0   jquerylib_0.1.4   
# [37] vctrs_0.3.8        tensorA_0.36.2     xfun_0.24          ps_1.6.0          
# [41] globals_0.14.0     proto_1.0.0        testthat_3.0.3     rvest_1.0.0       
# [45] lifecycle_1.0.0    renv_0.13.2        DEoptimR_1.0-9     MASS_7.3-54       
# [49] scales_1.1.1       hms_1.1.0          parallel_4.1.0     yaml_2.2.1        
# [53] memoise_2.0.0      gridExtra_2.3      sass_0.4.0         stringi_1.7.3     
# [57] desc_1.3.0         e1071_1.7-7        pkgbuild_1.2.0     rlang_0.4.11      
# [61] pkgconfig_2.0.3    compositions_2.0-1 evaluate_0.14      lattice_0.20-44   
# [65] processx_3.5.2     tidyselect_1.1.1   parallelly_1.27.0  plyr_1.8.6        
# [69] magrittr_2.0.1     bookdown_0.22      R6_2.5.0           generics_0.1.0    
# [73] DBI_1.1.1          pillar_1.6.1       haven_2.4.1        withr_2.4.2       
# [77] units_0.7-2        bayesm_3.1-4       modelr_0.1.8       crayon_1.4.1      
# [81] KernSmooth_2.23-20 utf8_1.2.1         tzdb_0.1.2         viridis_0.6.1     
# [85] grid_4.1.0         readxl_1.3.1       callr_3.7.0        reprex_2.0.0      
# [89] digest_0.6.27      classInt_0.4-3     munsell_0.5.0      viridisLite_0.4.0 
# [93] bslib_0.2.5.1      sessioninfo_1.1.1