knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>", 
  fig.height = 6,
  fig.width = 8,
  fig.path = "Report/", 
  echo = FALSE, message = FALSE, warning = FALSE
)


# library(ficomp)

devtools::load_all()

library(dplyr)
library(forcats)
library(ggplot2)
library(eurostat)
library(tidyr)
library(ggptt)
library(glue)

set_proj_theme()

data("data_main_total_a", "data_main_groups_a", "data_ameco")

base_year <- 2010
base_years <- 2000:2018
geos <- c(Finland = "FI", Sweden = "SE", Germany = "DE", France = "FR")
start_time <- "1995-01-01"
geo_trans <- geo_fi
nace0_trans <- nace0_fi
h_geos <- c("FI", "SE", "DE", "US")

Data

TODO

Yhdistelmä Eurostatin ja OECD:n National Accounts datasta

Maat ja vuodet.

data_main_groups_a %>% 
  filter(nace0 == "total") %>% 
  select(geo, time, values = nulc_aper_va) %>% 
  group_by(geo) %>% 
  mutate(tmin = min(time[!is.na(values)]), 
         tmax = max(time[!is.na(values)])) %>% 
  ungroup() %>% 
  mutate(selected = geo %in% c(eurostat_geos, oecd_geos_ulcq)) %>% 
  translate(geo, geo_trans) %>% 
  ggplot(aes(geo, ymin = tmin, ymax = tmax, colour = selected)) +
    geom_linerange(size = 2, colour = geo_col(2)[1]) +
    coord_flip() +
    scale_colour_manual(values = rev(geo_col(2)), guide = "none") +
    the_title_blank("y")

save_fig("A1_Eurostat_OECD_na")
data_ameco %>% 
  select(geo, time, values = nulc_aper) %>% 
  group_by(geo) %>% 
  mutate(is_value = !is.na(values)) %>% 
  ungroup() %>% 
  mutate(selected = geo %in% c(eurostat_geos, oecd_geos_ulcq)) %>% 
  translate(geo, geo_trans) %>% 
  ggplot(aes(geo, time, alpha = is_value)) +
    geom_line(size = 2) +
    coord_flip() +
    scale_alpha_manual(values = c(0,1), guide = "none") +
    # scale_colour_manual(values = rev(geo_col(2)), guide = "none") +
    the_title_blank("y")

save_fig("A1_ameco_na")

Nimellinen yksikkötyökustannus koko talous

Tunnit, taso (2018) ja suhteellinen (2017, koska Yhdysvallat)

data_main_groups_a %>% 
  filter(nace0 == "total") %>%
  select(geo, time, nulc_hw_va, nulc_hw_va_rel_imf) %>% 
  gather(vars, values, nulc_hw_va, nulc_hw_va_rel_imf) %>% 
  mutate(h_geo = fct_other(geo, keep = h_geos,other_level = "muut"),
         h_geo = fct_relevel(h_geo, h_geos),
         geo = fct_relevel(geo, rev(h_geos), after = Inf),
         size = !(geo %in% h_geo)) %>% 
  translate(h_geo, geo_trans) %>% 
  translate(vars, c(nulc_aper = "Indeksi", 
                    nulc_aper_rel_imf = "Suhteellinen indeksi")) %>% 
  ggplot(aes(time, values, group = geo, colour = h_geo, size = size)) +
  facet_wrap(~ vars) +
  geom_line() +
  scale_size_manual(values = c(2,1), guide = "none") +
  scale_colour_manual(values = geo_col(length(h_geos) + 1)) +
  the_title_blank(c("x", "l")) +
  scale_y_continuous(limits = c(70,130), expand = expansion(mult = 0, add = 0)) +
  labs(y = "indeksi, 2010 = 100")

save_fig("A2_nulc")
data_main_annual %>% 
  select(geo, time, nulc_aper) %>% 
  gather(vars, values, nulc_aper) %>% 
  mutate(h_geo = fct_other(geo, keep = tuku_geos,other_level = "muut"),
         h_geo = fct_relevel(h_geo, h_geos),
         geo = fct_relevel(geo, rev(h_geos), after = Inf),
         size = !(geo %in% h_geo)) %>% 
  translate(h_geo, geo_trans) %>% 
  translate(vars, c(nulc_aper = "Indeksi", 
                    nulc_aper_rel_imf = "Suhteellinen indeksi")) %>% 
  ggplot(aes(time, values, group = geo, colour = h_geo, size = size)) +
  geom_line() +
  scale_size_manual(values = c(2,1), guide = "none") +
  scale_colour_manual(values = c(geo_col(length(tuku_geos)), "grey75")) +
  the_title_blank(c("x", "l")) +
  scale_y_continuous(limits = c(70,130), expand = expansion(mult = 0, add = 0)) +
  labs(y = "indeksi, 2010 = 100")

save_fig("A_nulc_levels")
vars_rel <- c(nulc_aper_rel_ecfin20 = "omassa valuutassa", nulc_aper_eur_rel_ecfin20 = "samassa valuutassa")

data_main_annual %>% 
  filter(geo == "FI") %>%
  select(geo, time, names(vars_rel)) %>% 
  gather(vars, values, -geo, -time) %>% 
  group_by(geo, vars) %>% 
  mutate(values = rebase(values, time, base_year)) %>% 
  ungroup() %>% 
  translate(vars, vars_rel) %>% 
  ggplot(aes(time, values, color = vars)) +
  geom_line() +
  the_title_blank(c("x", "l")) +
  labs(y = glue("Indeksi, {base_year} = 100")) +
  the_legend_bot()

save_fig("a_nulc_aper_rel")
data_long_annual %>% 
  filter(geo == "FI") %>% 
  filter(time >= "1995-01-01") %>% 
  select(geo, time, nulc_var = nulc_aper_rel_ecfin15, 
         # rulc_var = rulc_aper_rel_ameco15, 
         out_var = gdp_ind_rel_ecfin15) %>% 
  mutate(nulc_var = rebase(1/nulc_var, time, base_year)) %>%
  # mutate(rulc_var = rebase(1/rulc_var, time, base_year)) %>%
  # mutate(out_var = 100* (out_var / lag(out_var) -1) + 100) %>% 
  gather(vars, values, -geo, -time) %>% 
  # mutate(h_geo = fct_other(geo, keep = h_geos,other_level = "muut"),
  #        geo = fct_relevel(geo, h_geos, after = Inf)) %>% 
  translate(geo, geo_fi) %>% 
  # translate(vars, c(nulc_aper_rel_imf = "ULCy, käänteinen", gdp_ind_rel_imf = "BKT", 
                    # exp_ind_rel_imf = "Vienti", XPERF = "Vientimenestys")) %>% 
  ggplot(aes(time, values, colour = vars)) +
  geom_line() +
  facet_wrap(~ geo, scales = "free") +
  scale_size_manual(values = c(2,1)) +
  the_title_blank()
data_ameco_long %>% 
  select(geo, time, nulc_aper, nulc_aper_usd_rel_ameco15) %>% 
  gather(vars, values, nulc_aper, nulc_aper_usd_rel_ameco15) %>% 
  mutate(h_geo = fct_other(geo, keep = h_geos,other_level = "muut"),
         h_geo = fct_relevel(h_geo, h_geos),
         geo = fct_relevel(geo, rev(h_geos), after = Inf),
         size = !(geo %in% h_geo)) %>% 
  translate(h_geo, geo_trans) %>% 
  translate(vars, c(nulc_aper = "Indeksi", 
                    nulc_aper_rel_imf = "Suhteellinen indeksi")) %>% 
  ggplot(aes(time, values, group = geo, colour = h_geo, size = size)) +
  facet_wrap(~ vars, scales = "free_y") +
  geom_line() +
  scale_size_manual(values = c(2,1), guide = "none") +
  scale_colour_manual(values = geo_col(length(h_geos) + 1)) +
  the_title_blank(c("x", "l")) +
  # scale_y_continuous(limits = c(70,130), expand = expansion(mult = 0, add = 0)) +
  labs(y = "indeksi, 2010 = 100")

 save_fig("A2_nulc_ameco")

Vaihtosuhdekorjattu

data_main_annual %>% 
  filter(geo == "FI") %>% 
  select(geo, time, 
         "Vaihtosuhdekorjattu" = nulc_aper_eur_atot_rel_ecfin20, 
        "Normaali" =  nulc_aper_eur_rel_ecfin20) %>% 
  gather(vars, values, -geo, -time) %>% 
  group_by(geo, vars) %>% 
  mutate(values = rebase(values, time, 2010),
         change = 100 * (values / lag(values) -1)) %>% 
  ungroup() %>% 
  gather(type, values, values, change) %>% 
  ggplot(aes(time, values, color = vars)) +
  facet_wrap(~type, scales = "free_y",
             labeller = labeller(type = c(change = "muutos, %", values = "indeksi, 2010 = 100"))) +
  geom_line()+
  the_title_blank(c("x", "l", "y")) +
  geom_hline(aes(yintercept = yint), 
             data = data.frame(yint = 0, type = "change")) +
  labs(y = glue("Indeksi, 2010 = 100")) +
  the_legend_bot() 

 save_fig("A_nulc_a_tot")

Nimellinen yksikkötyökustannus toimialaryhmittäin

Koko talous, yksityinen sektori (pl. vaikeasti mitattavat), teollisuus ja palvelut. Yksityinen ja teollisuus myös ilman eletroniikkateollisuutta.

data_main_groups_a %>% 
  select(geo, time, nace0, nulc_hw_va, nulc_hw_va_rel_imf) %>% 
  gather(vars, values, nulc_hw_va, nulc_hw_va_rel_imf) %>% 
  mutate(h_geo = fct_other(geo, keep = h_geos,other_level = "muut"),
         h_geo = fct_relevel(h_geo, h_geos),
         geo = fct_relevel(geo, rev(h_geos), after = Inf),
         size = !(geo %in% h_geo)) %>% 
  translate(h_geo, geo_trans) %>% 
  translate(vars, c(nulc_hw_va = "Indeksi", 
                    nulc_hw_va_rel_imf = "Suhteellinen indeksi")) %>% 
  translate(nace0, nace0_trans) %>% 
  ggplot(aes(time, values, group = geo, colour = h_geo, size = size)) +
  facet_grid(nace0 ~ vars) +
  geom_line() +
  scale_size_manual(values = c(2,1), guide = "none") +
  scale_colour_manual(values = geo_col(length(h_geos) + 1)) +
  the_title_blank(c("x", "l")) +
  scale_y_continuous(limits = c(70,130), expand = expansion(mult = 0, add = 0)) +
  labs(y = "indeksi, 2010 = 100")

save_fig("A3_nulc_nace0", height = 9)

Toimialaryhmät Suomelle

data_main_groups_a %>% 
  filter(geo == "FI") %>% 
  select(geo, time, nace0, nulc_hw_va, nulc_hw_va_rel_imf) %>% 
  gather(vars, values, nulc_hw_va, nulc_hw_va_rel_imf) %>% 
  # mutate(h_geo = fct_other(geo, keep = h_geos,other_level = "muut"),
  #        h_geo = fct_relevel(h_geo, h_geos),
  #        geo = fct_relevel(geo, rev(h_geos), after = Inf),
  #        size = !(geo %in% h_geo)) %>% 
  # translate(h_geo, geo_trans) %>% 
  translate(vars, c(nulc_hw_va = "Indeksi", 
                    nulc_hw_va_rel_imf = "Suhteellinen indeksi")) %>% 
  translate(nace0, nace0_trans) %>% 
  ggplot(aes(time, values, colour = nace0)) +
  facet_wrap( ~ vars) +
  geom_line() +
  scale_size_manual(values = c(2,1), guide = "none") +
  # scale_colour_manual(values = geo_col(length(h_geos) + 1)) +
  the_title_blank(c("x", "l")) +
  scale_y_continuous(limits = c(70,130), expand = expansion(mult = 0, add = 0)) +
  labs(y = "indeksi, 2010 = 100")

save_fig("A4_nulc_nace0_fi")

Koko talous ja yrityssektori (pl. vaikeasti mitattavat) Suomelle

data_main_groups_a %>% 
  filter(geo == "FI", nace0 %in% c("total", "private")) %>% 
  select(geo, time, nace0, nulc_hw_va, nulc_hw_va_rel_imf) %>% 
  gather(vars, values, nulc_hw_va, nulc_hw_va_rel_imf) %>% 
  # mutate(h_geo = fct_other(geo, keep = h_geos,other_level = "muut"),
  #        h_geo = fct_relevel(h_geo, h_geos),
  #        geo = fct_relevel(geo, rev(h_geos), after = Inf),
  #        size = !(geo %in% h_geo)) %>% 
  # translate(h_geo, geo_trans) %>% 
  translate(vars, c(nulc_aper = "Indeksi", 
                    nulc_aper_rel_imf = "Suhteellinen indeksi")) %>% 
  ggplot(aes(time, values, colour = nace0)) +
  facet_wrap( ~ vars) +
  geom_line() +
  scale_size_manual(values = c(2,1), guide = "none") +
  # scale_colour_manual(values = geo_col(length(h_geos) + 1)) +
  the_title_blank(c("x", "l")) +
  scale_y_continuous(limits = c(70,130), expand = expansion(mult = 0, add = 0)) +
  labs(y = "indeksi, 2010 = 100")

Nimellinen ja reaalinen yksikkötyökustannus Suomelle

data_main_groups_a %>% 
  filter(geo == "FI") %>% 
  select(geo, time, nace0, nulc_hw_va, nulc_hw_va_rel_imf, rulc_hw_va, rulc_hw_va_rel_imf) %>% 
  gather(vars, values, nulc_hw_va, nulc_hw_va_rel_imf, rulc_hw_va, rulc_hw_va_rel_imf) %>% 
  mutate(vars2 = fct_recode(vars, taso = "nulc_hw_va", taso = "rulc_hw_va",
                            suhteellinen = "nulc_hw_va_rel_imf", suhteellinen = "rulc_hw_va_rel_imf"),
         vars3 = fct_recode(vars, nimellinen = "nulc_hw_va", reaalinen = "rulc_hw_va",
                            nimellinen = "nulc_hw_va_rel_imf", reaalinen = "rulc_hw_va_rel_imf")) %>% 
  # mutate(h_geo = fct_other(geo, keep = h_geos,other_level = "muut"),
  #        h_geo = fct_relevel(h_geo, h_geos),
  #        geo = fct_relevel(geo, rev(h_geos), after = Inf),
  #        size = !(geo %in% h_geo)) %>% 
  # translate(h_geo, geo_trans) %>% 
  translate(vars, c(nulc_aper = "Indeksi", 
                    nulc_aper_rel_imf = "Suhteellinen indeksi")) %>% 
  translate(nace0, nace0_trans) %>% 
  ggplot(aes(time, values, colour = vars3)) +
  facet_grid(nace0 ~ vars2) +
  geom_line() +
  scale_size_manual(values = c(2,1), guide = "none") +
  # scale_colour_manual(values = geo_col(length(h_geos) + 1)) +
  the_title_blank(c("x", "l")) +
  scale_y_continuous(limits = c(70,130), expand = expansion(mult = 0, add = 0)) +
  labs(y = "indeksi, 2010 = 100")

save_fig("A_nulc_rulc_fi", height = 9)

Samassa valuutassa volatiliteetti paljon suurempi.

data_main_groups_a %>% 
  filter(geo %in% c("SE"),
         time >= start_time,
         nace0 == "total") %>% 
  select(geo, time, nulc_va_rel_imf, nulc_va_eur_rel_imf) %>% 
  gather(ind, values, -geo, -time, factor_key = TRUE) %>% 
  ggplot(aes(time, values, colour = ind)) +
  geom_line() +
  the_title_blank()
data_main_groups_a %>% 
    filter(nace0 == "total") %>% 
  select(geo, time, nulc_va_rel_imf, nulc_va_eur_rel_imf) %>% 
  left_join(select(ameco_lc, geo, time, nulc_aper_rel_ameco, nulc_aper_rel_ameco_usd,
                   nulc_aper_rel37_ameco, nulc_aper_rel37_ameco_usd,
                   nulc_aper_relEU_ameco, nulc_aper_relEU_ameco_usd), by = c("geo", "time")) %>% 
    filter(geo %in% c("US", "FI", "SE", "DE"),
         time >= start_time) %>% 
  gather(ind, values, -geo, -time, factor_key = TRUE) %>% 
  ggplot(aes(time, values, colour = ind)) +
  geom_line() +
  facet_wrap(~geo) +
  the_title_blank()
data_main_groups_a %>% 
    filter(nace0 == "total") %>% 
  select(geo, time, nulc_va, nulc_va_eur) %>% 
  left_join(select(ameco_lc, geo, time, nulc_aper, nulc_aper_eur), by = c("geo", "time")) %>% 
    filter(geo %in% c("US", "FI", "SE", "DE"),
         time >= start_time) %>% 
  gather(ind, values, -geo, -time, factor_key = TRUE) %>% 
  ggplot(aes(time, values, colour = ind)) +
  geom_line() +
  facet_wrap(~geo) +
  the_title_blank()
data_main_groups_a %>% 
    filter(nace0 == "total") %>% 
  select(geo, time, nulc_va_rel_imf, nulc_va_eur_rel_imf) %>% 
  left_join(select(ameco_lc, geo, time, nulc_aper_rel_ameco, nulc_aper_rel_ameco_usd), by = c("geo", "time")) %>% 
    filter(geo %in% c("US", "FI", "SE", "DE"),
         time >= start_time) %>% 
  # filter(geo == "SE") %>% 
  gather(ind, values, -geo, -time, factor_key = TRUE) %>% 
  ggplot(aes(time, values, colour = ind)) +
  geom_line() +
  facet_wrap(~geo) +
  the_title_blank()
data_main_groups_a %>% 
  select(-contains("__")) %>% 
  filter(nace0 == "total") %>% 
  select(-nace0) %>% 
  gather(vars, values, -geo, -time) %>% 
  mutate(h_geo = fct_other(geo, keep = h_geos,other_level = "muut"),
         geo = fct_relevel(geo, h_geos, after = Inf)) %>% 
  ggplot(aes(time, values, group = geo, colour = h_geo)) +
  geom_line() +
  facet_wrap(~ vars, scales = "free") +
  # scale_size_manual(values = c(2,1)) +
  the_title_blank()
data_main_groups_a %>%
  filter(nace0 %in% c("total", "total_exK"),
         geo == "FI") %>%
  select(geo, time, nace0, nulc_aper_va_eur_rel_ecfinnace, rulc_aper_va_rel_ecfinnace) %>%
  gather(vars, values, -geo, -time, -nace0) %>%
  ggplot(aes(time, values, colour = nace0)) +
  geom_line() +
  facet_wrap(~vars, nrow = 2)


data_main_groups_a %>%
  filter(
    # nace0 %in% c("total", "total_exK", "private", "private_ex26"),
         geo == "FI") %>% 
  select(geo, time, nace0, nulc_aper_va_eur_rel_ecfinnace, rulc_aper_va_rel_ecfinnace) %>%
  gather(vars, values, -geo, -time, -nace0) %>% 
  ggplot(aes(time, values, colour = vars)) +
  geom_line() +
  facet_wrap(~nace0)

ggsave_twitter("nace")
data_main_groups_a %>% 
  filter(nace0 == "total") %>% 
  select(geo, time, nulc_aper_va) %>% 
  spread(geo, nulc_aper_va) %>% 
  View()
data_main_groups_a %>%
  filter(
    # nace0 %in% c("total", "total_exK", "private", "private_ex26"),
         geo == "FI") %>% 
  select(geo, time, nace0, rulc_aper_va, rulc_aper_va_rel_ecfinnace) %>%
  gather(vars, values, -geo, -time, -nace0) %>% 
  ggplot(aes(time, values, colour = vars)) +
  geom_line() +
  facet_wrap(~nace0)


pttry/ficomp documentation built on June 11, 2024, 9:53 p.m.