knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
# library(ficomp) devtools::load_all() library(dplyr) library(tidyr) library(ggplot2) library(ggptt) set_ptt() data("weights_bis_narrow", "weights_bis_broad", "fi_goods_trade_dat", "fi_service_trade_dat", "data_main_annual")
weights_bis_narrow %>% filter(geo_base == "FI") %>% mutate(weight = tidyr::replace_na(weight, 0)) %>% mutate(geo_big = forcats::fct_lump_min(geo, 30, w = weight)) %>% group_by(time, geo_big) %>% summarise(weight = sum(weight)) %>% ungroup() %>% mutate(geo_big = forcats::fct_reorder2(geo_big, time, weight)) %>% ggplot(aes(time, weight, colour = geo_big)) + geom_line()
weights_bis_narrow %>% group_by(time, geo_base) %>% summarise(w = sum(weight, na.rm = TRUE)) %>% pull(w) %>% all(. == 100)
weights_bis_broad %>% filter(geo_base == "FI") %>% mutate(weight = tidyr::replace_na(weight, 0)) %>% mutate(geo_big = forcats::fct_lump_min(geo, 30, w = weight)) %>% group_by(time, geo_big) %>% summarise(weight = sum(weight)) %>% ungroup() %>% mutate(geo_big = forcats::fct_reorder2(geo_big, time, weight)) %>% ggplot(aes(time, weight, colour = geo_big)) + geom_line()
fi_goods_trade_dat %>% mutate(bis_narrow = geo %in% weights_bis_narrow$geo, bis_broad = geo %in% weights_bis_broad$geo, ec_fin19 = geo %in% weights_ecfin19$geo, ec_fin27 = geo %in% weights_ecfin27$geo, ec_fin37 = geo %in% weights_ecfin37$geo, imf = geo %in% weights_imf$geo) %>% group_by(flow, time) %>% summarise_at(vars(-geo, -values), ~(100 * sum(values * ., na.rm = TRUE) / values[geo == "TOTAL"])) %>% ungroup() %>% gather(share_ind, shares, -flow, -time) %>% ggplot(aes(time, shares, colour = share_ind)) + facet_wrap(~flow) + geom_line() + geom_h0()
fi_service_trade_dat %>% mutate(inc_narrow = geo %in% weights_bis_narrow$geo, inc_broad = geo %in% weights_bis_broad$geo) %>% group_by(flow, time) %>% summarise(share_narrow = 100 * sum(values * inc_narrow, na.rm = TRUE) / values[geo == "TOTAL"], share_broad = 100 * sum(values * inc_broad, na.rm = TRUE) / values[geo == "TOTAL"]) %>% ungroup() %>% gather(share_ind, shares, share_narrow, share_broad) %>% ggplot(aes(time, shares, colour = share_ind)) + facet_wrap(~flow) + geom_line() + geom_h0()
list_weight_funs <- function(...){ y <- purrr::map(list(...), ~substitute(weight_index(gdp_ind, geo, time, weight_df = .), parent.frame(2)) ) y} list_weight_funs(weights_bis_broad) data_main_annual %>% select(geo, time, nulc_aper) %>% group_by(time) %>% mutate(bis_broad = weight_index(nulc_aper, geo, time, weight_df = weights_bis_broad), bis_narrow = weight_index(nulc_aper, geo, time, weight_df = weights_bis_narrow), ecfin19 = weight_index(nulc_aper, geo, time, weight_df = weights_ecfin19, check_geos = FALSE), ecfin27 = weight_index(nulc_aper, geo, time, weight_df = weights_ecfin27, check_geos = FALSE), ecfin37 = weight_index(nulc_aper, geo, time, weight_df = weights_ecfin37, check_geos = FALSE), imf = weight_index(nulc_aper, geo, time, weight_df = weights_imf)) %>% select(-nulc_aper) %>% filter(geo == "FI") %>% gather(vars, values, -geo , -time) %>% ggplot(aes(time, values, colour = vars)) + geom_line()
list_weight_funs <- function(...){ y <- purrr::map(list(...), ~substitute(weight_index(gdp_ind, geo, time, weight_df = .), parent.frame(2)) ) y} list_weight_funs(weights_bis_broad) data_main_annual %>% select(geo, time, nulc_aper_eur, nulc_aper) %>% group_by(time) %>% mutate(eur__bis_15 = weight_index2(nulc_aper_eur, geo, time, geos = eurostat_geos, weight_df = weights_bis_broad), eur__ecfin_15 = weight_index2(nulc_aper_eur, geo, time, geos = eurostat_geos, weight_df = weights_ecfin37), eur__imf_15 = weight_index2(nulc_aper_eur, geo, geos = eurostat_geos, time, weight_df = weights_imf), eur__ecfin_20 = weight_index2(nulc_aper_eur, geo, geos = geo20, time, weight_df = weights_ecfin37), own__bis_15 = weight_index2(nulc_aper, geo, time, geos = eurostat_geos, weight_df = weights_bis_broad), own__ecfin_15 = weight_index2(nulc_aper, geo, time, geos = eurostat_geos, weight_df = weights_ecfin37), own__imf_15 = weight_index2(nulc_aper, geo, geos = eurostat_geos, time, weight_df = weights_imf), own__ecfin_20 = weight_index2(nulc_aper, geo, geos = geo20, time, weight_df = weights_ecfin37) ) %>% select(-nulc_aper_eur, -nulc_aper) %>% filter(geo == "FI") %>% gather(vars, values, -geo , -time) %>% separate(vars, into = c("type", "vars"), sep = "__") %>% translate(type, c(own = "Omassa valuutassa", eur = "Euroissa")) %>% mutate(vars = toupper(gsub("_", " ", vars))) %>% ggplot(aes(time, values, colour = vars)) + geom_line() + facet_wrap(~ type) + the_title_blank()
data_ameco %>% filter(time >= 1995) %>% group_by(time) %>% mutate(nulc_aper_eur_rel_ecfin_15 = weight_index2(nulc_aper_eur, geo, time, geos = eurostat_geos, weight_df = weights_ecfin37), nulc_aper_eur_rel_ecfin_15_ex = weight_index2(nulc_aper_eur, geo, time, geos = (eurostat_geos), weight_df = weights_ecfin37), nulc_aper_eur_rel_ecfin_20 = weight_index2(nulc_aper_eur, geo, geos = geo20, time, weight_df = weights_ecfin37), ) %>% select(geo, time, nulc_aper_usd_rel_ameco15, nulc_aper_usd_rel_ameco24, nulc_aper_usd_rel_ameco37, nulc_aper_eur_rel_ecfin_15, nulc_aper_eur_rel_ecfin_20) %>% filter(geo == "FI") %>% gather(vars, values, -geo, -time) %>% ggplot(aes(time, values, color = vars)) + geom_line()
data_long_annual %>% select(geo, time, nulc_aper_eur_rel_ecfin15, nulc_aper_eur_rel_ecfin20, rulc_aper_rel_ecfin20) %>% # select(geo, time, B1GQ__CLV15_MNAC) %>% filter(geo == "FI") %>% gather(vars, values, -geo, -time) %>% #spread(geo, values) %>% View() ggplot(aes(time, values, color = vars)) + facet_wrap(~ geo) + geom_line()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.