This is the sotkanet R package to access data from the Sotkanet portal that provides over 2000 demographic indicators across Finland and Europe, maintained by the National Institute for Health and Welfare (THL). For more information, see Information about Sotkanet and API description. This package is part of rOpenGov.
NOT_CRAN <- identical(tolower(Sys.getenv("NOT_CRAN")), "true") knitr::opts_chunk$set( collapse = TRUE, comment = "#>", purl = NOT_CRAN, eval = NOT_CRAN )
Release version from CRAN:
install.packages("sotkanet")
Development version from GitHub:
library(devtools) install_github("ropengov/sotkanet")
Load sotkanet and other libraries used in this vignette
library(sotkanet) library(knitr) library(magrittr) library(kableExtra)
List available Sotkanet indicators:
# Using a pre-defined list of indicators for a smaller download sotkanet.indicators <- SotkanetIndicators(id = c(4,5,6,7,46,74), type = "table") kable(head(sotkanet.indicators))
List geographical regions with available indicators:
# options(width = 60) sotkanet.regions <- SotkanetRegions(type = "table") kable(head(sotkanet.regions))
Get the indicator no. 10013 (Unemployment rate of young people aged 16-24 years) from Sotkanet, from Finland (Suomi) for 1990-2012 (Eurostat employment statistics youth unemployment), and plot a graph:
# Get indicator data dat <- GetDataSotkanet(indicators = 10013, years = 1990:2012, genders = c('female', 'male', 'total'), region.category = "EUROOPPA", regions = "Suomi") # Investigate the first lines in the data kable(head(dat)) %>% kable_styling() %>% kableExtra::scroll_box(width = "100%")
Download and visualize time series:
# Pick indicator name indicator.name <- as.character(unique(dat$indicator.title.fi)) indicator.source <- as.character(unique(dat$indicator.organization.title.fi)) # Visualize library(ggplot2) theme_set(theme_bw(20)); p <- ggplot(dat, aes(x = year, y = primary.value, group = gender, color = gender)) p <- p + geom_line() + ggtitle(paste(indicator.name, indicator.source, sep = " / ")) p <- p + labs(x = "Year", y = "Value", caption = "Data source: https://sotkanet.fi") p <- p + theme(title = element_text(size = 10)) p <- p + theme(axis.title.x = element_text(size = 20)) p <- p + theme(axis.title.y = element_text(size = 20)) p <- p + theme(legend.title = element_text(size = 15)) print(p)
Investigate the effect of municipality size on demographic variation. Smaller municipalities show more random variation as expected by statistical arguments:
selected.inds <- c(127, 178) dat <- GetDataSotkanet(indicators = selected.inds, years = 2011, genders = c('total')) # Pick necessary fields and remove duplicates datf <- dat[, c("region.title.fi", "indicator.title.fi", "primary.value")] datf <- datf[!duplicated(datf),] dw <- reshape(datf, idvar = "region.title.fi", timevar = "indicator.title.fi", direction = "wide") names(dw) <- c("Municipality", "Population", "Migration") p <- ggplot(dw, aes(x = log10(Population), y = Migration)) + geom_point(size = 3) ggtitle("Migration vs. population size") theme(title = element_text(size = 15)) theme(axis.title.x = element_text(size = 20)) theme(axis.title.y = element_text(size = 20)) theme(legend.title = element_text(size = 15)) print(p)
This takes for a long time and is not recommended for regular use. Save the data on your local disk for further work.
# These indicators have problems with R routines: problematic.indicators <- c(1575, 1743, 1826, 1861, 1882, 1924, 1952, 2000, 2001, 2033, 2050, 3386, 3443) # Get data for all indicators datlist <- list() for (ind in setdiff(sotkanet.indicators$indicator, problematic.indicators)) { datlist[[as.character(ind)]] <- GetDataSotkanet(indicators = ind, years = 1990:2013, genders = c('female', 'male', 'total')) } # Combine tables (this may require considerable time and memory # for the full data set) dat <- do.call("rbind", datlist)
For further usage examples, see rOpenGov-blog, and takomo, and Helsinki Region Infoshare-blog
Cite SOTKAnet and link to https://sotkanet.fi/sotkanet/fi/index. Also mention indicator provider.
Central points:
This work can be freely used, modified and distributed under the Two-clause BSD license.
citation("sotkanet")
This vignette was created with
sessionInfo()
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.