### Preparation ### devtools::install_url("https://renkulab.io/gitlab/dscc/metadata-auto-r-library/-/archive/v002/metadata-auto-r-library-v002.tar.gz") library(fso.metadata) library(ggplot2) library(tidyverse) ### 1. Get a codelist ### # All languages codelist <- get_codelist(identifier='CL_NOGA_SECTION') head(codelist, 3) # In french codelist_fr <- get_codelist(identifier='CL_NOGA_SECTION', language='fr') head(codelist_fr, 3) ### 2. Get a nomenclature of one level ### # All language: Level 1 nomenclature <- get_nomenclature_one_level( identifier='HCL_CH_ISCO_19_PROF', level_number=2 ) head(nomenclature, 3) # French: Level 2 nomenclature_fr <- get_nomenclature_one_level( identifier='HCL_CH_ISCO_19_PROF', level_number=1, language='fr' ) head(nomenclature_fr, 5) ### 3. Get a nomenclature of multiple levels ### # French multi_nomenclature_fr <- get_nomenclature_multiple_levels( identifier='HCL_CH_ISCO_19_PROF', level_from=1, level_to=6, language='fr' ) head(multi_nomenclature_fr, 10) ### 4. Concrete example from Mr. van Nieuwkoop with Noga Data load("data/pkagg.Rdata") head(pk_agg$A88) noga2 <- as_tibble(get_codelist(identifier='CL_NOGA_DIVISION', language='it')) names(noga2) <- c('id', 'label', 'name') head(noga2) # Get the completely disaggregated production accounts # and join them with the noga2 descriptions a88 <- pk_agg$A88 %>% left_join(noga2, by = c("Code" = "id")) head(a88) # Filter and prepare data a88_filtered <- a88 %>% select(-Beschreibung, -name) %>% relocate(label, .after = Code) %>% rename(Department = label, Year = Jahr, Component = Komponent) %>% select(Code, Department, Component, Year, Nominal) %>% filter( Nominal > 0) %>% filter(!is.na(Department)) %>% # keep filter(Code %in% c("01","02", "03")) # keep first 3 department # Plot the intermediate consumption (CI), the value added (VA), and the # production value (VP) for the section A (agriculture) ggplot(a88_filtered, aes(Year, Nominal, color = Component)) + geom_line() + ylab("in Mio. CHF") + facet_wrap(~Department, scales = "free")