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


# library(ficomp)

devtools::load_all()

library(dplyr)
library(forcats)
library(ggplot2)
library(tidyr)
library(ggptt)
library(glue)
library(ggthemes)
library(purrr)

set_board_theme(base_size = 10)
fig_height <- 10

data("data_main_annual")

pdat_annual <- data_main_annual %>% 
  filter(time >= 2000)

mean_range <- 2000:(max(data_main_annual$time))

geos <- c(Suomi = "FI", Ruotsi = "SE", Saksa = "DE", Ranska = "FR", 
          euroalue = "EA19", "Itävalta" = "AT", Espanja = "ES")

Suomen nimelliset yksikkötyökustannusindeksit

Eri määritelmillä laskettuna

q_dat %>% 
  filter(geo == "FI",
         time >= "1995-01-01") %>% 
  select(geo, time, nulc, nulc_va, nulc_hw, nulc_hw_va, nulc_aper, nulc_aper_va) %>% 
  gather(ind, values, -geo, -time) %>% 
  group_by(geo, ind) %>% 
  mutate(change = 100 * (values / lag(values, 4, order_by = time) - 1)) %>% 
  ungroup() %>% 
  gather(vars, values, values, change) %>% 
  translate(vars, c(change = "Muutos, %", values = "Taso, indeksi 2010 = 100")) %>% 
  translate(ind, gsub("yrittäjäkorjaus ", "yk ", var_labels_fi), simple = TRUE, parts = c(4,5)) %>%
  ggplot(aes(time, values, colour = ind)) +
  facet_wrap(~ vars, scales = "free_y") +
  geom_line() +
  geom_hline(aes(yintercept = yint), 
             data = data.frame(yint = 0, vars = "Muutos, %")) +
  the_title_blank() +
  the_legend_bot() +
  guides(colour = guide_legend(nrow = 3))

# save_board_figs("Kuvio_5_1", height = fig_height, save_data = TRUE)

Koko talouden nimelliset suhteelliset yksikkötyökustannukset

pdat_annual %>%  # select(time, geo, nulc_aper) |> spread(geo, nulc_aper) |> tail()
  filter(geo == "FI") %>% 
  select(geo, time, 
         "Omassa valuutassa" = nulc_aper_rel_ecfin17, 
         "Samassa valuutassa" = nulc_aper_eur_rel_ecfin17) %>% 
  gather(vars, values, -geo, -time) %>% 
  group_by(geo, vars) %>% 
  mutate(values = rebase(values, time, mean_range)) %>% 
  ungroup() %>% 
  ggplot(aes(time, values, color = vars)) +
  geom_line() +
  the_title_blank(c("x", "l")) +
  geom_hline(yintercept = 100) +
  labs(y = glue("Indeksi, keskiarvo {min(mean_range)} - {max(mean_range)} = 100")) +
  the_legend_bot() 

save_board_figs("Kuvio_5_2", height = fig_height, save_data = TRUE)

Nimellisen suhteellisen yksikkötyökustannuksen osatekijät

Suhteessa 16 keskiseen verrokkimaahan: r paste0(geo17, collapse = ", ")

pdat_annual %>% 
  filter(geo == "FI") %>% 
  mutate(exch_eur_ind_rel_ecfin17 = 1/ exch_eur_ind_rel_ecfin17) %>% 
  select(geo, time, 
         "Tuottavuus" = lp_ind_rel_ecfin17, 
         "Palkansaajakorvaukset" =  d1_per_ind_rel_ecfin17, 
         "Valuuttakurssi" = exch_eur_ind_rel_ecfin17) %>% 
  gather(vars, values, -geo, -time) %>% 
  group_by(geo, vars) %>% 
  mutate(values = rebase(values, time, mean_range)) %>% 
  ungroup() %>% 
  ggplot(aes(time, values, color = vars)) +
  geom_line() +
  the_title_blank(c("x", "l")) +
  geom_hline(yintercept = 100) +
  labs(y = glue("Indeksi, keskiarvo {min(mean_range)}–{max(mean_range)} = 100")) +
  the_legend_bot()

save_board_figs("Kuvio_2_2", height = fig_height, save_data = TRUE)

save_board_figs("Kuvio_2_2_en", plot = ggptt::translate_plot(last_plot(), fig_translation), height = fig_height, save_data = TRUE)

Vaihtosuhdekorjattu

pdat_annual %>% 
  filter(geo == "FI") %>% 
  select(geo, time, 
         "Vaihtosuhdekorjattu" = nulc_aper_eur_atot_rel_ecfin17, 
        "Normaali" =  nulc_aper_eur_rel_ecfin17) %>% 
  gather(vars, values, -geo, -time) %>% 
  group_by(geo, vars) %>% 
  mutate(values = rebase(values, time, mean_range)) %>% 
  ungroup() %>% 
  ggplot(aes(time, values, color = vars)) +
  geom_line() +
  the_title_blank(c("x", "l")) +
  geom_hline(yintercept = 100) +
  labs(y = glue("Indeksi, keskiarvo {min(mean_range)} - {max(mean_range)} = 100")) +
  the_legend_bot()
data_main_annual %>% 
  filter(geo == "FI") %>% 
  select(geo, time, 
         "Vaihtosuhdekorjattu" = nulc_aper_eur_atot_rel_ecfin17, 
        "Normaali" =  nulc_aper_eur_rel_ecfin17) %>% 
  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_board_figs("Kuvio_5_4", height = fig_height, save_data = TRUE)

SUomen suhteelliset yksikkötyökustannusindeksit

Eri määritelmillä

pdat_annual %>% 
  filter(geo == "FI") %>% 
  select(geo, time, 
         "Nimellinen, vaihtosuhdekorjattu" = nulc_aper_eur_atot_rel_ecfin17, 
        "Nimellinen, samassa valuutassa" =  nulc_aper_eur_rel_ecfin17,
        "Reaalinen" =  rulc_aper_rel_ecfin17, 
        "Nimellinen, omassa valuutassa" = nulc_aper_rel_ecfin17) %>% 
  gather(vars, values, -geo, -time) %>% 
  group_by(geo, vars) %>% 
  mutate(values = rebase(values, time, mean_range)) %>% 
  ungroup() %>% 
  ggplot(aes(time, values, color = vars)) +
  geom_line() +
  the_title_blank(c("x", "l")) +
  geom_hline(yintercept = 100) +
   labs(y = glue("Indeksi, keskiarvo {min(mean_range)}–{max(mean_range)} = 100")) +
  the_legend_bot() +
  guides(color = guide_legend(nrow = 2)) 

save_board_figs("Kuvio_2_1", height = fig_height, save_data = TRUE)



save_board_figs("Kuvio_2_1_en", plot = ggptt::translate_plot(last_plot(), fig_translation), height = fig_height, save_data = TRUE)

Suhteelliset nimelliset eri painoin

Nimelliset yksikkötykustannukset

k <- 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_17 = weight_index2(nulc_aper_eur, geo, geos = geo17, 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_17 = weight_index2(nulc_aper, geo, geos = geo17, time, weight_df = weights_ecfin37)
         ) %>% 
  select(-nulc_aper_eur, -nulc_aper) %>%
  filter(geo == "FI") %>% 
  gather(vars, values, -geo , -time)

k %>% 
  group_by(geo, vars) %>% 
  mutate(values = rebase(values, time, mean_range)) %>% 
  ungroup() %>%
  separate(vars, into = c("type", "vars"), sep = "__") %>% 
  mutate(
    type = fct_recode(type, !!!c("Omassa valuutassa" = "own", "Samassa valuutassa" ="eur")),
    vars = toupper(gsub("_", " ", vars))) %>%
  ggplot(aes(time, values, colour = vars)) +
  geom_line() +
  facet_wrap(~ type) +
  scale_x_continuous(labels = no_century) +
  the_title_blank(c("x", "l")) +
  geom_hline(yintercept = 100) +
  labs(y = glue("Indeksi, keskiarvo {min(mean_range)} - {max(mean_range)} = 100")) +
  the_legend_bot()

save_board_figs("Kuvio_5_3", height = fig_height, save_data = TRUE)

Neljännesvuosi-indikaattorit

covid_geo <- c("FI", "SE", "DE", "DK", "IT", "AT", "ES")

q_dat %>% 
  select(time, geo, "Palkansaajakorvaukset" = d1_hw_ind, "Yksikkötyökustannukset" = nulc_hw_va_eur, "Työn tuottavuus" = lp_hw_ind) %>% 
  gather(vars, values, -geo, -time) %>% 
  group_by(geo, vars) %>% 
  mutate(values = rebase(values, time, 2019)) %>% 
  ungroup() %>% 
  filter(geo %in% covid_geo, time >= "2019-01-01") %>% 
  mutate(geo = fct_relevel(geo, covid_geo)) %>%
  mutate(high_geo = geo == "FI") %>% 
  translate(geo, geo_fi) %>% 
  ggplot(aes(time, values, color = geo, size = high_geo)) +
  facet_wrap(~ vars) +
  geom_line() +
  scale_size_manual(values = c(1, 2), guide = "none") +
  scale_x_date(date_labels = "%Y", date_breaks = "1 year") +
  the_title_blank(c("x", "l")) +
  labs(y = "indeksi, 2015 = 100") +
  the_legend_bot()


save_board_figs("Kuvio_5_3", height = fig_height, save_data = TRUE) 

save_board_figs("Kuvio_5_3_en", plot = ggptt::translate_plot(last_plot(), fig_translation), height = fig_height, save_data = TRUE)
covid_geo <- c("FI", "SE", "DE", "DK", "IT", "AT", "ES")

q_dat %>% 
  select(
    time,
    geo,
    "Palkasaajakorvaukset" = d1_hw_ind,
    "Yksikkötyökustannukset" = nulc_hw_va_eur,
    "Työn tuottavuus" = lp_hw_ind,
    "BKT" = gdp_ind,
    "Työllisyys" = emp_ind,
    "Työtunnit" = EMP_DC__THS_HW
  ) %>% 
  gather(vars, values, -geo, -time) %>% 
  group_by(geo, vars) %>% 
  mutate(values = rebase(values, time, 2019)) %>% 
  ungroup() %>% 
  filter(geo %in% covid_geo, time >= "2019-01-01") %>% 
  mutate(geo = fct_relevel(geo, covid_geo)) %>%
  mutate(high_geo = geo == "FI") %>% 
  translate(geo, geo_fi) %>% 
  ggplot(aes(time, values, color = geo, size = high_geo)) +
  facet_wrap(~ vars) +
  geom_line() +
  scale_size_manual(values = c(1, 2), guide = "none") +
  the_title_blank(c("x", "l")) +
  labs(y = "indeksi, 2019 = 100") +
  the_legend_bot()
q_dat %>% 
  select(time, geo, EMP_DC__THS_HW) %>% 
  gather(vars, values, -geo, -time) %>% 
  group_by(geo, vars) %>% 
  mutate(values = rebase(values, time, 2019)) %>% 
  ungroup() %>% 
  filter(geo %in% covid_geo, time >= "2019-01-01") %>% 
  mutate(geo = fct_relevel(geo, covid_geo)) %>%
  mutate(high_geo = geo == "FI") %>% 
  translate(geo, geo_fi) %>% 
  ggplot(aes(time, values, color = geo, size = high_geo)) +
  facet_wrap(~ vars) +
  geom_line() +
  scale_size_manual(values = c(1, 2), guide = "none") +
  the_title_blank(c("x", "l")) +
  labs(y = "indeksi, 2019 = 100") +
  the_legend_bot()
q_dat %>% 
  select(time, geo, "Palkasaajakorvaukset" = d1_hw_ind, "Yksikkötyökustannukset" = nulc_hw_va_eur, "Työn tuottavuus" = lp_hw_ind) %>% 
  gather(vars, values, -geo, -time) %>% 
  group_by(geo, vars) %>% 
  mutate(values = rebase(values, time, 2015)) %>% 
  ungroup() %>% 
  filter(time >= "2015-01-01") %>% 
  mutate(geo = fct_relevel(geo, covid_geo)) %>%
  mutate(high_geo = geo == "FI") %>% 
  translate(geo, geo_fi) %>% 
  ggplot(aes(time, values, color = geo, size = high_geo)) +
  facet_wrap(~ vars) +
  geom_line() +
  scale_size_manual(values = c(1, 2), guide = "none") +
  the_title_blank(c("x", "l")) +
  labs(y = "indeksi, 2015 = 100") +
  the_legend_bot()

Palkansaajakorvaukset

Kansantalouden tilinpidossa ja Työvoimakustannusindeksissä (lc_lci_r2_q)

covid_geo <- c("FI", "SE", "DE", "DK", "IT", "AT", "ES")

q_dat %>% 
  select(time, geo, 
         "Kansantalouden tilinpito" = d1_hw_ind, 
        "Työvoimakustannusindeksi" =  d1net_hw_ind) %>% 
  gather(vars, values, -geo, -time) %>% 
  group_by(geo, vars) %>% 
  mutate(values = rebase(values, time, 2015)) %>% 
  ungroup() %>% 
  filter(geo %in% covid_geo, time >= "2015-01-01") %>% 
  mutate(geo = fct_relevel(geo, covid_geo)) %>%
  mutate(high_geo = geo == "FI") %>% 
  translate(geo, geo_fi) %>% 
  ggplot(aes(time, values, color = vars)) +
  facet_wrap(~ geo) +
  geom_line() +
  scale_size_manual(values = c(1, 2), guide = "none") +
  the_title_blank(c("x", "l")) +
  labs(y = "indeksi, 2015 = 100") +
  the_legend_bot()


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