knitr::opts_chunk$set(fig.path='Figs_slide/', echo=FALSE, warning=FALSE, message=FALSE,
                      fig.height=5, fig.width=6, dpi=300, out.width = "650px")

devtools::load_all()

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

set_ptt()

theme_update(
  plot.subtitle = element_text(colour = "grey40"),
  plot.caption = element_text(size = 10, face = "plain", colour = "grey40"),
  text = element_text(face = "bold"),
  plot.margin = margin(1, 1, 3, 1))
met_dat <- eurostat::get_eurostat("met_gind3", time_format = "num")

tran_dat <- eurostat::get_eurostat("lfsi_long_q")
tran_urb_dat <- eurostat::get_eurostat("lfsi_long_e03")

countries <- c("BE", "DE", "FR", "IE", "NL", "AT", "FI", "SE", "DK")

Metropolialueiden muutto

# eurostat::ea_countries



net_met_mig <- met_dat %>% 
  filter(indic_de %in% c("CNMIGRAT", "JAN")) %>%   # netmigration and population january
  filter(!grepl("_NM", metroreg)) %>% 
  mutate(country = substr(metroreg, 1, 2)) %>%   # countrycode
  filter(country %in% countries) %>% 
  spread(indic_de, values) 


net_met_mig %>% 
  group_by(time) %>% 
  summarise_if(is.numeric, sum) %>% 
  mutate(metroreg = "Keskimäärin") %>% 
  bind_rows(net_met_mig) %>% 
  mutate(net_mig_share = 100 * CNMIGRAT / JAN) %>% 
  mutate(high_reg = fct_other(metroreg, keep = c("FI001MC", "FI002M", "FI003M", "Keskimäärin"), 
                              other_level = "muut"),
         metroreg = fct_relevel(metroreg, c("FI001MC", "FI002M", "FI003M", "Keskimäärin"), 
                                after = Inf)) %>% 
  ggplot(aes(time, net_mig_share, group = metroreg, colour = high_reg, alpha = high_reg)) +
  geom_line() +
  scale_alpha_manual(values = c(1,1,1,1,0.2)) +
  geom_h0() +
  coord_cartesian(ylim = c(-1, 2.5))

Transitio työttömyydestä

 trans_pdat <- tran_dat %>% 
  filter(geo %in% countries,
         indic_em == "U_E",      # Unemployment to employment
         sex == "T",
         unit == "PC_UNE") %>%   # Percentage of unemployment
  mutate(high_geo = fct_other(geo, keep = c("FI"), 
                              other_level = "muut"),
         geo = fct_relevel(geo, c("FI"), after = Inf)) %>% 
  mutate(time = as.numeric(time))

# hchart(trans_pdat, "line", hcaes(x = time, y = values)) 

 trans_pdat %>% 
  ggplot(hcaes(x = time, y = values, group = geo, colour = high_geo)) +
  geom_line()

Transitio työttömyydestä urbanisaatio

 trans_urb_pdat <- tran_urb_dat %>% 
  filter(geo %in% countries,
         age == "Y25-54",
         unit == "PC_UNE") %>%   # Percentage of unemployment
  mutate(high_geo = fct_other(geo, keep = c("FI"), 
                              other_level = "other"),
         geo = fct_relevel(geo, c("FI"), after = Inf)) %>%  
  mutate(deg_urb = fct_recode(deg_urb, Cities = "DEG1",
                                       "Towns and suburbs" = "DEG2",
                                       "Rural areas" = "DEG3"))


geo_list <-  glue_collapse(countries, sep  = ", ", last = " and ")

trans_urb_pdat %>% 
  ggplot(hcaes(x = time, y = values, group = geo, colour = high_geo)) +
  facet_wrap(~ deg_urb) + 
  geom_line() + 
  labs(title = "Transition probabilities from unemployment to employment, age 25-54",
      subtitle = glue::glue("Countries: {geo_list}"),
      caption = "Source: Eurostat (exprerimental)",
      y = "Percentage of unemployment", x = NULL)


pttry/KT162R documentation built on Nov. 27, 2022, 3:52 a.m.