Estimated average age of young people leaving the parental household by sex - yth_demo_030

Data - Eurostat

unit

Code
yth_demo_030 %>%
  left_join(unit, by = "unit") %>%
  group_by(unit, Unit) %>%
  summarise(Nobs = n()) %>%
  arrange(-Nobs) %>%
  {if (is_html_output()) print_table(.) else .}
unit Unit Nobs
AVG Average 2115

sex

Code
yth_demo_030 %>%
  left_join(sex, by = "sex") %>%
  group_by(sex, Sex) %>%
  summarise(Nobs = n()) %>%
  arrange(-Nobs) %>%
  {if (is_html_output()) print_table(.) else .}
sex Sex Nobs
F Females 705
M Males 705
T Total 705

2018 Map

Code
europe_NUTS0_new <- yth_demo_030 %>%
  filter(sex == "T",
         time == "2018") %>%
  select(geo, values) %>%
  right_join(europe_NUTS0 %>%
               filter(long >= -10,
                      lat >= 20), by = "geo") %>%
  group_by(geo, values) %>%
  summarise(long = mean(long), lat = mean(lat))

yth_demo_030 %>%
  filter(sex == "T",
         time == "2018") %>%
  select(geo, values) %>%
  right_join(europe_NUTS0 %>%
               filter(long >= -10,
                      lat >= 20), by = "geo") %>%
  ggplot(aes(x = long, y = lat)) +
  geom_polygon(aes(group = group, fill = values)) + coord_map() +
  scale_fill_viridis_c(na.value = "white",
                       labels = dollar_format(a = 1, p = "", su = ""),
                       breaks = seq(0, 80, 2)) +
  geom_text(aes(label = values), data = europe_NUTS0_new,  size = 3, hjust = 0.5) +
  theme_void() + theme(legend.position = c(0.25, 0.85)) + 
  labs(fill = "Average age of young people \nleaving the parental household")

Gif

Code
europe_NUTS0_new <- yth_demo_030 %>%
  filter(sex == "T") %>%
  mutate(year = as.integer(time)) %>%
  select(geo, year, values) %>%
  right_join(europe_NUTS0 %>%
               filter(long >= -10,
                      lat >= 20), by = "geo") %>%
  group_by(geo, year, values) %>%
  summarise(long = mean(long), lat = mean(lat))

options(gganimate.nframes = 50, gganimate.end_pause = 10)
yth_demo_030 %>%
  filter(sex == "T") %>%
  mutate(year = as.integer(time)) %>%
  select(year, geo, values) %>%
  left_join(europe_NUTS0 %>%
               filter(long >= -10,
                      lat >= 20), by = "geo") %>%
  arrange(year) %>%
  na.omit %>%
  ggplot(aes(x = long, y = lat)) +
  geom_polygon(aes(group = group, fill = values)) + coord_map() +
  scale_fill_viridis_c(na.value = "white",
                       labels = dollar_format(a = 1, p = "", su = ""),
                       breaks = seq(0, 80, 2)) +
  theme_void() + theme(legend.position = c(0.25, 0.85)) + 
  labs(fill = "Average age of young people \nleaving the parental household") + 
  {if(!is_latex_output())transition_time(year)} +
  {if(!is_latex_output())labs(title = "Year: {frame_time}")}