INXPI104_raw <-
"INXPI104" %>%
statgl_url(lang = language) %>%
statgl_fetch(
"level of education" = px_all(),
unit = 3,
gender = 1:2,
age = c(0, 4),
"type of income" = 1,
time = px_all(),
.col_code = TRUE
) %>%
as_tibble()
INXPI104 <-
INXPI104_raw %>%
filter(
value != "NA",
age == unique(INXPI104_raw %>% pull(age))[1]
) %>%
rename(
"edu" = `level of education`,
"type" = `type of income`
) %>%
mutate(
edu = edu %>% fct_inorder(),
type = type %>% str_remove_all("[:digit:]|[:punct:]|\\+") %>% trimws()
)
INXPI104 %>%
ggplot(aes(
x = time %>% as.numeric(),
y = value,
color = gender %>% fct_rev()
)) +
geom_line(size = 2) +
facet_wrap(~ edu) +
theme_statgl() +
scale_color_statgl() +
scale_y_continuous(labels = function(x) format(x, big.mark = ".", scientific = FALSE)) +
scale_x_continuous(breaks = scales:: pretty_breaks()) +
labs(
title = INXPI104 %>% pull(type) %>% unique(),
subtitle = INXPI104 %>% pull(unit) %>% unique(),
x = " ",
y = " ",
color = " ",
caption = sdg5$figs$fig1$cap[language]
)
INXPI104 <-
INXPI104_raw %>%
filter(
value != "NA",
age == unique(INXPI104_raw %>% pull(age))[2]
) %>%
rename(
"edu" = `level of education`,
"type" = `type of income`
) %>%
mutate(
edu = edu %>% fct_inorder(),
type = type %>% str_remove_all("[:digit:]|[:punct:]|\\+") %>% trimws()
)
INXPI104 %>%
ggplot(aes(
x = time %>% as.numeric(),
y = value,
color = gender %>% fct_rev()
)) +
geom_line(size = 2) +
facet_wrap(~ edu) +
theme_statgl() +
scale_color_statgl() +
scale_y_continuous(labels = function(x) format(x, big.mark = ".", scientific = FALSE)) +
scale_x_continuous(breaks = scales:: pretty_breaks()) +
labs(
title = paste0(
INXPI104 %>% pull(type) %>% unique(), ", ",
INXPI104 %>% pull(age) %>% unique()
),
subtitle = INXPI104 %>% pull(unit) %>% unique(),
x = " ",
y = " ",
color = " ",
caption = sdg5$figs$fig1$cap[language]
)
# Fejl, Nordic Statistics
Nordic Statistics # Import
SOXOU01_raw <-
statgl_url("SOXOU01", lang = language) %>%
statgl_fetch(
"inventory variable" = c("Andel50", "Andel60"),
gender = 1:2,
year = px_all(),
.col_code = TRUE
) %>%
as_tibble()
# Transform
SOXOU01 <-
SOXOU01_raw %>%
mutate(
year = year %>% make_date(),
gender = gender %>% fct_inorder()
)
# Plot
SOXOU01 %>%
mutate(`inventory variable` = `inventory variable` %>% str_to_sentence()) %>%
ggplot(aes(
x = year,
y = value,
fill = gender)) +
geom_col(position = "dodge") +
scale_y_continuous(labels = scales::percent_format(
scale = 1,
accuracy = 1,
big.mark = ".",
decimal.mark = ",")
) +
facet_wrap(~ `inventory variable`) +
theme_statgl() +
scale_fill_statgl(reverse = TRUE) +
labs(
title = sdg5$figs$fig3$title[language],
subtitle = sdg5$figs$fig3$sub[language],
x = " ",
y = " ",
fill = " ",
caption = sdg5$figs$fig3$cap[language]
)
# Import
UDXTKK_raw <-
statgl_url("UDXTKK", lang = language) %>%
statgl_fetch(subject = px_all(),
grade = px_all(),
sex = 1:2,
unit = "B",
time = px_all(),
.col_code = TRUE
) %>%
as_tibble()
# Transform
UDXTKK <-
UDXTKK_raw %>%
mutate(
time = time %>% make_date(),
subject = subject %>% fct_inorder()
)
fig_legend <- statgl_url("UDXTKK", lang = language) %>% statgl_fetch() %>% select(1) %>% colnames()
fig_title <- (statgl_url("UDXTKK", lang = language) %>% statgl_meta())$title
fig_subtitle <- UDXTKK_raw[["unit"]] %>% unique()
# Plot
UDXTKK %>%
ggplot(aes(
x = time,
y = value,
color = subject
)) +
geom_line(size = 2) +
facet_grid(grade ~ sex) +
theme_statgl() +
scale_color_statgl() +
scale_y_continuous(labels = scales::percent_format(
scale = 1,
accuracy = 1,
big.mark = ".",
decimal.mark = ","
)) +
labs(
title = fig_title,
subtitle = fig_subtitle,
x = " ",
y = " ",
color = fig_legend,
caption = sdg5$figs$fig4$cap[language]
)
# Import
UDXFKK_raw <-
statgl_url("UDXFKK", lang = language) %>%
statgl_fetch(unit = "Avg",
grade = "FO",
subject = c("01", "02", "03", "04"),
"type of grades" = 56:58,
sex = 1:2,
time = px_all(),
.col_code = TRUE) %>%
as_tibble()
# Transform
UDXFKK <-
UDXFKK_raw %>%
separate(`type of grades`, c("split1", "split2"), " - ") %>%
mutate(split2 = split2 %>% str_to_title(),
split1 = split1 %>% str_to_lower(),
time = time %>% make_date()) %>%
unite(combi, 2, 4, sep = ", ")
fig_title <- (statgl_url("UDXFKK", lang = language) %>% statgl_meta())$title
fig_y <- UDXFKK[["unit"]] %>% unique() %>% str_to_title()
fig_subtitle <- UDXFKK[["combi"]] %>% unique()
# Plot
UDXFKK %>%
ggplot(aes(
x = time,
y = value,
color = sex
)) +
geom_line(size = 2) +
facet_grid(split2 ~ subject) +
scale_y_continuous(labels = scales::unit_format(
suffix = " ",
big.mark = ".",
decimal.mark = ",",
accuracy = 1
)) +
theme_statgl() +
scale_color_statgl(guide = guide_legend(reverse = TRUE)) +
labs(
title = fig_title,
subtitle = fig_subtitle,
x = " ",
y = fig_y,
color = " ",
caption = sdg5$figs$fig5$cap[language]
)
# Import
UDXISCPROD_raw <-
statgl_url("UDXISCPROD", lang = language) %>%
statgl_fetch("level of education" = px_all(),
gender = px_all(),
time = px_all(),
age = "35-39",
.col_code = TRUE) %>%
as_tibble()
# Transform
UDXISCPROD <-
UDXISCPROD_raw %>%
filter(`level of education` != UDXISCPROD_raw[[1]][1]) %>%
mutate(
`level of education` = `level of education` %>% factor(level = unique(`level of education`) %>% rev()),
time = time %>% make_date()
)
# Plot
UDXISCPROD %>%
arrange(`level of education`) %>%
ggplot(aes(
x = time,
y = value,
fill = `level of education`
)) +
geom_area(position = "fill") +
facet_wrap(~ gender) +
scale_y_continuous(labels = scales::percent_format(
scale = 100,
accuracy = 1,
big.mark = ".",
decimal.mark = ","
)) +
theme_statgl() +
scale_fill_statgl(reverse = TRUE, guide = guide_legend(reverse = TRUE, nrow = 3)) +
labs(
title = sdg5$figs$fig6$title[language],
subtitle = unique(UDXISCPROD[["age"]]),
x = " ",
y = " ",
fill = NULL,
caption = sdg5$figs$fig6$cap[language]
)
# Import
ARXBFB1_raw <-
statgl_url("ARXBFB1", lang = language) %>%
statgl_fetch(
time = px_all(),
industry = 1:16,
gender = 1:2,
"inventory variable" = 1,
.col_code = TRUE
) %>%
as_tibble()
# Transform
ARXBFB1 <-
ARXBFB1_raw %>%
mutate(
time = time %>% make_date(),
industry = industry %>% fct_reorder(value) %>% fct_rev()
) %>%
arrange(industry)
# Plot
ARXBFB1 %>%
ggplot(aes(
x = time,
y = value,
fill = gender
)) +
geom_area() +
facet_wrap(~ industry, scales = "free", labeller = label_wrap_gen()) +
theme_statgl(base_size = 8) +
scale_fill_statgl(reverse = TRUE) +
scale_y_continuous(labels = scales::unit_format(
suffix = " ",
big.mark = ".",
decimal.mark = ","
)) +
labs(
title = unique(ARXBFB1[[4]]),
subtitle = sdg5$figs$fig7$title[language],
x = " ",
y = sdg5$figs$fig7$y_lab[language],
fill = " ",
caption = sdg5$figs$fig7$cap[language]
)
# Import
ARXLED4_raw <-
statgl_url("ARXLED4", lang = language) %>%
statgl_fetch(
time = px_all(),
gender = 1:2,
age = px_all(),
.col_code = TRUE
) %>%
as_tibble()
# Transform
ARXLED4 <-
ARXLED4_raw %>%
mutate(
time = time %>% make_date(),
age = age %>% factor(levels = unique(age))
)
# Plot
ARXLED4 %>%
ggplot(aes(
x = time,
y = value,
color = gender
)) +
geom_line(size = 2) +
facet_wrap(~ age, scales = "free") +
theme_statgl() + scale_color_statgl(reverse = TRUE) +
scale_y_continuous(labels = scales::percent_format(
scale = 1,
accuracy = 1,
big.mark = ".",
decimal.mark = ",")) +
labs(
title = sdg5$figs$fig8$title[language],
subtitle = sdg5$figs$fig8$sub[language],
x = " ",
y = " ",
color = " ",
caption = sdg5$figs$fig8$cap[language]
)