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.
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
List available Sotkanet indicators:
# Using a pre-defined list of indicators for a smaller download
SotkanetIndicators(id = c(4,5,6,7,46,74), type = "table")
sotkanet.indicators <-kable(head(sotkanet.indicators))
List geographical regions with available indicators:
# options(width = 60)
SotkanetRegions(type = "table")
sotkanet.regions <-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
GetDataSotkanet(indicators = 10013, years = 1990:2012,
dat <-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
as.character(unique(dat$indicator.title.fi))
indicator.name <- as.character(unique(dat$indicator.organization.title.fi))
indicator.source <-
# Visualize
library(ggplot2)
theme_set(theme_bw(20));
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))
p <-print(p)
Investigate the effect of municipality size on demographic variation. Smaller municipalities show more random variation as expected by statistical arguments:
c(127, 178)
selected.inds <- GetDataSotkanet(indicators = selected.inds,
dat <-years = 2011, genders = c('total'))
# Pick necessary fields and remove duplicates
dat[, c("region.title.fi", "indicator.title.fi", "primary.value")]
datf <- datf[!duplicated(datf),]
datf <- reshape(datf, idvar = "region.title.fi",
dw <-timevar = "indicator.title.fi", direction = "wide")
names(dw) <- c("Municipality", "Population", "Migration")
ggplot(dw, aes(x = log10(Population), y = Migration)) +
p <- 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:
c(1575, 1743, 1826, 1861, 1882, 1924, 1952, 2000,
problematic.indicators <-2001, 2033, 2050, 3386, 3443)
# Get data for all indicators
list()
datlist <-for (ind in setdiff(sotkanet.indicators$indicator, problematic.indicators)) {
as.character(ind)]] <- GetDataSotkanet(indicators = ind,
datlist[[years = 1990:2013, genders = c('female', 'male', 'total'))
}
# Combine tables (this may require considerable time and memory
# for the full data set)
do.call("rbind", datlist) dat <-
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")
#>
#> Kindly cite the sotkanet R package as follows:
#>
#> Leo Lahti, Einari Happonen, Juuso Parkkinen, Joona Lehtomaki, Vesa
#> Saaristo and Pyry Kantanen (rOpenGov 2022). sotkanet: Sotkanet Open
#> Data Access and Analysis. R package version 0.9.79
#> https://github.com/rOpenGov/sotkanet
#>
#> A BibTeX entry for LaTeX users is
#>
#> @Misc{,
#> title = {sotkanet: Sotkanet Open Data Access and Analysis},
#> author = {Leo Lahti and Einari Happonen and Joona Lehtomäki and Juuso Parkkinen and Joona Lehtomaki and Vesa Saaristo and Pyry Kantanen},
#> url = {https://github.com/rOpenGov/sotkanet},
#> year = {2022},
#> note = {R package version 0.9.79},
#> }
#>
#> Many thanks for all contributors!
This vignette was created with
sessionInfo()