# Helper function:
age_adjust <- function(count, pop, rate = NULL, stdpop){
if (missing(count) & !missing(pop) & is.null(rate)) {
count <- rate * pop
}
if (missing(pop) & !missing(count) & is.null(rate)) {
pop <- count/rate
pop[!is.finite(pop)] <- 0
}
if (is.null(rate) & !missing(count) & !missing(pop)){
rate <- count/pop
rate[!is.finite(rate)] <- 0
}
cruderate <- sum(count)/sum(pop)
stdwt <- stdpop/sum(stdpop)
dsr <- sum(stdwt * rate)
tibble(`crude_rate` = cruderate, `std_rate` = dsr)
}
# Import
SUDA2_raw <-
statgl_url("SUXA2", lang = "da") |>
statgl_fetch(.eliminate_rest = FALSE) |>
as_tibble() |>
rename(Aborter = value)
# Tidy
SUDA_2 <-
SUDA2_raw |>
as_tibble() |>
spread(enhed, Aborter) |>
mutate_at(c(1, 2), strtoi)
# Standardize
SUDA_2_2000 <- SUDA_2 |> filter(tid == 2000) |> pull(Middelfolketal)
SUDA2_std <-
SUDA_2 |>
group_by(tid) |>
summarise(age_adjust(Aborter, Middelfolketal, stdpop = SUDA_2_2000) * 1000)
# Plot
SUDA2_std |>
ggplot(aes(x = tid, y = std_rate)) +
geom_line(size = 2, color = statgl:::statgl_cols("darkblue"))+
theme_statgl() +
theme(plot.margin = margin(10, 10, 10, 10)) +
labs(
title = sdg3$figs$fig1$title[language],
x = " ",
y = sdg3$figs$fig1$y_lab[language],
subtitle = sdg3$figs$fig1$sub[language],
caption = sdg3$figs$fig1$cap[language]
)
# Import
BEXBBDTB_raw <-
"BEXBBDTB" |>
statgl_url(lang = "da") |>
statgl_fetch(
"place of birth" = "N",
gender = "t",
age = 0:1,
calcbase = "q5",
measure = "ex",
time = px_all(),
.col_code = TRUE
) |>
as_tibble()
# Plot
BEXBBDTB_raw |>
ggplot(aes(
x = as.numeric(time),
y = value,
color = age
)) +
geom_line(size = 2) +
theme_statgl() +
scale_color_statgl() +
scale_y_continuous(labels = scales::unit_format(
suffix = " ",
big.mark = ".",
decimal.mark = ","
)) +
labs(
title = sdg3$figs$fig2$title[language],
subtitle = sdg3$figs$fig2$sub[language],
x = " ",
y = BEXBBDTB_raw[["measure"]][[1]],
color = sdg3$figs$fig2$color[language],
caption = sdg3$figs$fig2$cap[language]
)
# Helper function:
age_adjust <- function(count, pop, rate = NULL, stdpop){
if (missing(count) & !missing(pop) & is.null(rate)) {
count <- rate * pop
}
if (missing(pop) & !missing(count) & is.null(rate)) {
pop <- count/rate
pop[!is.finite(pop)] <- 0
}
if (is.null(rate) & !missing(count) & !missing(pop)){
rate <- count/pop
rate[!is.finite(rate)] <- 0
}
cruderate <- sum(count)/sum(pop)
stdwt <- stdpop/sum(stdpop)
dsr <- sum(stdwt * rate)
tibble(`crude_rate` = cruderate, `std_rate` = dsr)
}
# Import
BEDBBDM1_raw <-
statgl_url("BEXBBDM1", lang = "da") |>
statgl_fetch(
type = px_all(),
age = px_all(),
.col_code = TRUE) |>
as_tibble() |>
rename(c(
"alder" = 1,
"art" = 2,
"tid" = 3,
"Dødsfald" = 4
))
BEDBBM1 <-
BEDBBDM1_raw |>
as_tibble() |>
spread(art, Dødsfald) |>
mutate_at(1:2, strtoi)
BEDBBM1_2000 <-
BEDBBM1 |>
filter(tid == 2000) |>
pull(Middelfolketal)
BEDBBM1_std <- BEDBBM1 |>
group_by(tid) |>
summarise(age_adjust(Døde, Middelfolketal, stdpop = BEDBBM1_2000) * 1000) |>
ungroup()
BEDBBM1_std |>
ggplot(aes(
x = tid,
y = std_rate
)) +
geom_line(size = 2, color = statgl:::statgl_cols("darkblue")) +
theme_statgl() +
labs(
title = sdg3$figs$fig4$title[language],
subtitle = sdg3$figs$fig4$sub[language],
y = sdg3$figs$fig4$y_lab[language],
x = " ",
caption = sdg3$figs$fig4$cap[language]
)
# Helper function:
age_adjust <- function(count, pop, rate = NULL, stdpop){
if (missing(count) & !missing(pop) & is.null(rate)) {
count <- rate * pop
}
if (missing(pop) & !missing(count) & is.null(rate)) {
pop <- count/rate
pop[!is.finite(pop)] <- 0
}
if (is.null(rate) & !missing(count) & !missing(pop)){
rate <- count/pop
rate[!is.finite(rate)] <- 0
}
cruderate <- sum(count)/sum(pop)
stdwt <- stdpop/sum(stdpop)
dsr <- sum(stdwt * rate)
tibble(`crude_rate` = cruderate, `std_rate` = dsr)
}
# Import
BEDBBDM1_raw <-
statgl_url("BEXBBDM1", lang = language) |>
statgl_fetch(
type = px_all(),
age = px_all(),
gender = c("M", "K"),
.col_code = TRUE) |>
as_tibble()
BEDBBDM1 <-
BEDBBDM1_raw |>
as_tibble() |>
spread(type, value) |>
mutate_at(c(1, 3), strtoi) |>
rename(c("Death" = 4, "Meanpopulation" = 5))
BEDBBDM1_2000 <-
BEDBBDM1 |>
arrange(time, gender, age) |>
filter(time == 2000) |>
pull(Meanpopulation)
BEDBBDM1_std <-
BEDBBDM1 |>
group_by(time, gender) |>
arrange(age) |>
summarise(age_adjust(Death, Meanpopulation, stdpop = BEDBBDM1_2000) * 1000) |>
ungroup()
BEDBBDM1_std |>
ggplot(aes(
x = time,
y = std_rate,
color = gender
)) +
geom_line(size = 2) +
theme_statgl() +
scale_color_statgl(reverse = TRUE) +
labs(
title = sdg3$figs$fig5$title[language],
subtitle = sdg3$figs$fig5$sub[language],
color = " ",
x = " ",
y = sdg3$figs$fig5$y_lab[language],
caption = sdg3$figs$fig4$cap[language]
)
# Import
DISE01_raw <-
"https://pxweb.nhwstat.org:443/Prod/sq/31c3d851-c0ad-4728-8ee0-9b2b252cc48b.csv" |>
read_csv() |>
as_tibble()
# Transform
DISE01 <-
DISE01_raw |>
pivot_longer(cols = c(`Greenland Men`, `Greenland Women`), names_to = "sex", values_to = "Greenland") |>
mutate(
sex = sex |> str_replace("Greenland Men", sdg3$figs$fig6$groups$group1[language] |> unlist()),
sex = sex |> str_replace("Greenland Women", sdg3$figs$fig6$groups$group2[language] |> unlist()),
Greenland = as.numeric(Greenland)
) |>
filter(Year > 2002)
# Plot
DISE01 |>
ggplot(aes(
x = Year,
y = Greenland,
color = sex
)) +
geom_line(size = 2) +
theme_statgl() +
scale_color_statgl(reverse = TRUE) +
labs(
title = sdg3$figs$fig6$title[language],
subtitle = sdg3$figs$fig6$sub[language],
x = " ",
y = sdg3$figs$fig6$y_lab[language],
color = " ",
caption = sdg3$figs$fig6$cap[language]
)
# Import
SUDLDM2_raw <-
read_csv(paste0("https://bank.stat.gl:443/sq/3efbaaab-3db0-4b90-8f7b-18c556afe4e4", "?lang=", language),
locale = locale(encoding = "latin1"))
BEDSTM1_raw <-
read_csv(paste0("https://bank.stat.gl:443/sq/e8c2ed7c-ed03-471b-87e1-40d658b78bd4", "?lang=", language))
# Transform
Selvmord <-
SUDLDM2_raw |>
left_join(BEDSTM1_raw) |>
rename(
"cause" = 1,
"time" = 2,
"suicide" = 3,
"population" = 4
) |>
mutate(rate = suicide / population * 10^5,
time = time |> make_date()) |>
filter(rate > 0)
# Plot
Selvmord |>
ggplot(aes(
x = time,
y = rate,
color = statgl:::statgl_cols("darkblue")
)) +
geom_line(size = 2) +
theme_statgl() + scale_color_statgl() +
theme(legend.position = "none") +
labs(
title = Selvmord[[1]][1],
x = " ",
y = sdg3$figs$fig7$y_lab[language],
caption = sdg3$figs$fig7$cap[language]
)
# Import, dødelighed
BEXBBDM1_raw <-
statgl_url("BEXBBDM1", lang = language) |>
statgl_fetch(
age = 0:4,
type = "D",
.col_code = TRUE
) |>
as_tibble()
# Import, levendefødte
BEXBBLK1_raw <-
statgl_url("BEXBBLK1", lang = language) |>
statgl_fetch(
type = "L",
.col_code = TRUE
) |>
as_tibble()
child_mortality <-
BEXBBDM1_raw |>
spread(2, 4) |>
spread(1, 3) |>
mutate(sum = `0` + `1` + `2` + `3` + `4`) |>
select(-(2:6)) |>
left_join(BEXBBLK1_raw |> spread(1, 3)) |>
rename(
"mortality" = 2,
"population" = 3
) |>
mutate(rate = mortality / population * 1000,
time = time |> make_date())
# Plot
child_mortality |>
ggplot(aes(
x = time,
y = rate,
color = statgl:::statgl_cols("darkblue")
)) +
geom_line(size = 2, color = statgl:::statgl_cols("darkblue")) +
expand_limits(y = 0) +
theme_statgl() +
labs(
title = sdg3$figs$fig8$title[language],
subtitle = sdg3$figs$fig8$sub[language],
x = " ",
y = sdg3$figs$fig8$y_lab[language],
caption = sdg3$figs$fig8$cap[language]
)
url <- paste0("https://bank.stat.gl:443/api/v1/", language, "/Greenland/AL/AL10/ALXALK1.px")
# Import
ALXALK1_raw <-
url |>
statgl_fetch(
unit = 1,
type = 0:2,
category = 1,
.col_code = TRUE
) |>
as_tibble()
# Transform
ALXALK1 <-
ALXALK1_raw |>
mutate(time = time |> make_date())
# Plot
ALXALK1 |>
ggplot(aes(
x = time,
y = value,
fill = type
)) +
geom_area() +
theme_statgl() +
scale_fill_statgl(palette = "autumn") +
labs(
title = sdg3$figs$fig9$title[language],
subtitle = sdg3$figs$fig9$sub[language],
x = " ",
y = sdg3$figs$fig9$y_lab[language],
fill = sdg3$figs$fig9$fill[language],
caption = sdg3$figs$fig9$cap[language]
)
url <- paste0("https://bank.stat.gl:443/api/v1/", language, "/Greenland/AL/AL40/ALXTOB2.px")
# Import
ALXTOB2_raw <-
url |>
statgl_fetch(
unit = 3,
type = 0:1,
.col_code = TRUE
) |>
as_tibble()
# Transform
ALXTOB2 <-
ALXTOB2_raw |>
mutate(time = time |> make_date())
# Plot
ALXTOB2 |>
ggplot(aes(
x = time,
y = value,
fill = type
)) +
geom_area() +
theme_statgl() +
theme(plot.margin = margin(10, 10, 10, 10)) +
scale_fill_statgl(palette = "autumn") +
scale_y_continuous(labels = scales::comma_format(
decimal.mark = ",",
big.mark = "."
)) +
labs(
title = sdg3$figs$fig10$title[language],
subtitle = sdg3$figs$fig10$sub[language],
x = " ",
y = sdg3$figs$fig10$y_lab[language],
fill = sdg3$figs$fig10$fill[language],
caption = sdg3$figs$fig10$cap[language]
)
# Import
OFXOA1_raw <-
statgl_url("OFXOA1", lang = language) |>
statgl_fetch(
`inventory variable` = px_all(),
.col_code = TRUE
) |>
as_tibble()
# Transform
OFXOA1 <-
OFXOA1_raw |>
mutate(
time = time |> make_date(),
value = value * 10^-3
)
# Plot
OFXOA1 |>
ggplot(aes(
x = time,
y = value,
fill = `inventory variable`
)) +
geom_col(position = "dodge") +
theme_statgl() +
scale_fill_statgl(reverse = TRUE) +
labs(
title = sdg3$figs$fig11$title[language],
x = " ",
y = sdg3$figs$fig11$y_lab[language],
fill = " ",
caption = sdg3$figs$fig11$cap[language]
)
# Import
BEDLL1_raw <-
statgl_url("BEXLL1", lang = language) |>
statgl_fetch(
time = px_all(),
weight = 0:9,
.col_code = TRUE
) |>
as_tibble()
# Transform
BEDLL1 <-
BEDLL1_raw |>
mutate(
time = time |> as.numeric(),
weight = weight |> str_remove("gram") |> trimws(),
weight = weight |> factor(levels = unique(weight))
) |>
filter(time %in% quantile(time)[-1])
# Plot
BEDLL1 |>
ggplot(aes(
x = weight,
y = value,
fill = time |> as.factor()
)) +
geom_col(position = "dodge2") +
theme_statgl() +
theme(text = element_text(size = 20)) +
scale_fill_statgl() +
labs(
title = sdg3$figs$fig12$title[language],
x = sdg3$figs$fig12$x_lab[language],
y = sdg3$figs$fig12$y_lab[language],
fill = " ",
caption = sdg3$figs$fig12$cap[language]
)
# Import
a <- c(3, 6, 16, 37, 49, 56, 3, 8, 24, 37, 52, 55, 2, 2, 6, 25, 43, 49, 1.5, 2, 6, 15, 26, 52)
b <- rep(c(11, 12, 13, 14, 15, 16), 4)
c <- c(rep(2006, 6), rep(2010, 6), rep(2014, 6), rep(2018, 6))
# Transform
hbsc <-
data.frame(a, b, c) |>
as_tibble() |>
rename(
"value" = 1,
"age" = 2,
"time" = 3
) |>
mutate(age = age |> factor(levels = unique(age)))
# Plot
hbsc |>
ggplot(aes(
x = age,
y = value,
fill = age
)) +
geom_col() +
facet_wrap(~ time) +
xlab("age") +
scale_y_continuous(labels = scales::percent_format(
scale = 1,
big.mark = ".",
decimal.mark = ","
)) +
theme_statgl() +
scale_fill_statgl() +
theme(legend.position = "none") +
labs(
title = sdg3$figs$fig13$title[language],
x = sdg3$figs$fig13$x_lab[language],
y = " ",
caption = sdg3$figs$fig13$cap[language]
)
key1 <- sdg3$figs$fig14$keys$key1[language] |> unlist()
key2 <- sdg3$figs$fig14$keys$key2[language] |> unlist()
key3 <- sdg3$figs$fig14$keys$key3[language] |> unlist()
# Import
a <- c(6, 3, 4, 2, 3, 2)
b <- rep(c(2014, 2018), 3)
c <- c(rep(key1, 2), rep(key2, 2), rep(key3, 2))
hbsc <-
data.frame(b, a, c) |>
as_tibble() |>
rename(
"time" = 1,
"value" = 2,
"key" = 3
) |>
mutate(
key = key |> factor(levels = unique(key)),
time = time |> factor(levels = unique(time))
)
# Plot
hbsc |>
ggplot(aes(
x = time,
y = value,
fill = time
)) +
geom_col() +
facet_wrap(~ key) +
scale_y_continuous(labels = scales::percent_format(
scale = 1,
big.mark = ".",
decimal.mark = ","
)) +
theme_statgl() +
scale_fill_statgl() +
theme(legend.position = "none") +
xlab("time") +
labs(
title = sdg3$figs$fig14$title[language],
y = " ",
x = " ",
caption = sdg3$figs$fig14$cap[language]
)
key1 <- sdg3$figs$fig15$keys$key1[language] |> unlist()
key2 <- sdg3$figs$fig15$keys$key2[language] |> unlist()
key3 <- sdg3$figs$fig15$keys$key3[language] |> unlist()
# Import
a <- c(27, 15, 17, 12, 9, 8)
b <- rep(c(2014, 2018), 3)
c <- c(rep(key1, 2), rep(key2, 2), rep(key3, 2))
# Transform
hbsc <-
data.frame(b, c, a) |>
as_tibble() |>
rename(
"time" = 1,
"key" = 2,
"value" = 3
) |>
mutate(
key = key |> factor(levels = unique(key)),
time = time |> factor(levels = unique(time))
)
# Plot
hbsc |>
ggplot(aes(
x = time,
y = value,
fill = key
)) +
geom_col() +
facet_wrap(~ key) +
scale_y_continuous(labels = scales::percent_format(
scale = 1,
big.mark = ".",
decimal.mark = ","
)) +
theme_statgl() +
scale_fill_statgl() +
theme(legend.position = "none") +
labs(
title = sdg3$figs$fig15$title[language],
y = " ",
x = " ",
caption = sdg3$figs$fig15$cap[language]
)
# Import
a <- c(92,90,82,56,35,24,89,84,70,52,29,21,80,83,82,82,80,74,98,98,96,84,68,51)
b <- c(rep(2006, 6), rep(2010, 6), rep(2014, 6), rep(2018, 6))
c <- rep(11:16, 4)
# Transform
hbsc <-
data.frame(b, c, a) |>
as_tibble() |>
rename(
time = 1,
age = 2,
value = 3
) |>
mutate(
time = time |> factor(levels = unique(time)),
)
# Plot
hbsc |>
ggplot(aes(
x = age,
y = value,
color = time
)) +
geom_line(size = 2) +
scale_y_continuous(labels = scales::percent_format(
scale = 1,
big.mark = ".",
decimal.mark = ","
)) +
theme_statgl() +
scale_color_statgl() +
labs(
title = sdg3$figs$fig16$title[language],
y = sdg3$figs$fig16$y_lab[language],
x = sdg3$figs$fig16$x_lab[language],
color = " ",
caption = sdg3$figs$fig16$cap[language]
)
# Import
key1 <- sdg3$figs$fig17$keys$key1[language] |> unlist()
key2 <- sdg3$figs$fig17$keys$key2[language] |> unlist()
a <- c(33, 30, 27, 24, 24, 24, 15, 18)
b <- rep(c(2006, 2010, 2014, 2018), 2)
c <- c(rep(key1, 4), rep(key2, 4))
# Transform
hbsc <-
data.frame(b, c, a) |>
as_tibble() |>
rename(
"time" = 1,
"gender" = 2,
"value" = 3
) |>
mutate(gender = gender |> factor(levels = unique(gender)))
# Plot
hbsc |>
ggplot(aes(
x = time,
y = value,
color = gender
)) +
geom_line(size = 2) +
scale_y_continuous(labels = scales::percent_format(
scale = 1,
big.mark = ".",
decimal.mark = ","
)) +
theme_statgl() +
scale_color_statgl() +
labs(
title = sdg3$figs$fig17$title[language],
y = sdg3$figs$fig17$y_lab[language],
x = " ",
color = " ",
caption = sdg3$figs$fig17$cap[language]
)
# Import
key1 <- sdg3$figs$fig18$keys$key1[language] |> unlist()
key2 <- sdg3$figs$fig18$keys$key2[language] |> unlist()
key3 <- sdg3$figs$fig18$keys$key3[language] |> unlist()
key4 <- sdg3$figs$fig18$keys$key4[language] |> unlist()
key5 <- sdg3$figs$fig18$keys$key5[language] |> unlist()
a <- c(3,3, 11,9,57,58,26,26,3,4)
b <- c(rep(key1, 2), rep(key2, 2), rep(key3, 2), rep(key4, 2), rep(key5, 2))
c <- rep(c(2014, 2018), 5)
# Transform
hbsc <-
data.frame(c, b, a) |>
as_tibble() |>
rename(
"time" = 1,
"key" = 2,
"value" = 3
) |>
mutate(
time = time |> factor(levels = unique(time)),
key = key |> factor(levels = unique(key))
)
# Plot
hbsc |>
ggplot(aes(
x = key,
y = value,
fill = time
)) +
geom_col(position = "dodge2") +
scale_y_continuous(labels = scales::percent_format(
scale = 1,
big.mark = ".",
decimal.mark = ","
)) +
theme_statgl() +
scale_fill_statgl() +
labs(
title = sdg3$figs$fig18$title[language],
y = " ",
x = " ",
fill = " ",
caption = sdg3$figs$fig18$cap[language]
)
# Import
key1 <- sdg3$figs$fig19$keys$key1[language] |> unlist()
key2 <- sdg3$figs$fig19$keys$key2[language] |> unlist()
key3 <- sdg3$figs$fig19$keys$key3[language] |> unlist()
a <- c(32,22,20,23,14,35,38,34,9,31,44,41,42,13,35)
b <- rep(c(2002,2006,2010,2014,2018), 3)
c <- c(rep(key1, 5), rep(key2, 5), rep(key3, 5))
# Transform
hbsc <-
data.frame(b, c, a) |>
as_tibble() |>
rename(
"time" = 1,
"key" = 2,
"value" = 3
) |>
mutate(key = key |> factor(levels = unique(key)))
# Plot
hbsc |>
ggplot(aes(
x = time,
y = value,
color = key
)) +
geom_line(size = 2) +
scale_y_continuous(labels = scales::percent_format(
scale = 1,
big.mark = ".",
decimal.mark = ","
)) +
theme_statgl() +
scale_color_statgl() +
labs(
title = sdg3$figs$fig19$title[language],
x = " ",
y = " ",
color = " ",
caption = sdg3$figs$fig19$cap[language]
)
# Import
key1 <- sdg3$figs$fig20$keys$key1[language] |> unlist()
key2 <- sdg3$figs$fig20$keys$key2[language] |> unlist()
key3 <- sdg3$figs$fig20$keys$key3[language] |> unlist()
a <- c(50,31,19,61,24,16,63,27,10,64,28,8)
b <- rep(c(2006,2010,2014,2018), 3)
c <- rep(c(key1, key2, key3), 4)
# Transform
hbsc <-
data.frame(b, c, a) |>
as_tibble() |>
rename(
"time" = 1,
"key" = 2,
"value" = 3
) |>
mutate(
key = key |> factor(levels = unique(key)),
time = time |> factor(levels = unique(time))
)
# Plot
hbsc |>
ggplot(aes(
x = key,
y = value,
fill = key
)) +
geom_col() +
facet_wrap(~ time, nrow = 1) +
scale_y_continuous(labels = scales::percent_format(
scale = 1,
big.mark = ".",
decimal.mark = ","
)) +
theme_statgl() +
scale_fill_statgl(guide = guide_legend(nrow = 3)) +
theme(axis.text.x = element_blank()) +
labs(
title = sdg3$figs$fig20$title[language],
y = " ",
x = " ",
fill = " ",
caption = sdg3$figs$fig20$cap[language]
)
# Import
key1 <- sdg3$figs$fig21$keys$key1[language] |> unlist()
key2 <- sdg3$figs$fig21$keys$key2[language] |> unlist()
key3 <- sdg3$figs$fig21$keys$key3[language] |> unlist()
key4 <- sdg3$figs$fig21$keys$key4[language] |> unlist()
a <- c(1732, 272, 547, 1485, 1887, 382, 668, 1609, 636, 106, 182, 560)
b <- c(rep(2019, 4), rep(2020, 4), rep(2021, 4))
c <- rep(c(key1, key2, key3, key4), 3)
# Transform
tusaannga <-
data.frame(b, c, a) |>
as_tibble() |>
rename(
"time" = 1,
"key" = 2,
"value" = 3
) |>
mutate(key = key |> factor(levels = unique(key)))
tusaannga |>
filter(!key %in% c(key1, key2)) |>
ggplot(aes(
x = time,
y = value,
fill = key
)) +
geom_col() +
theme_statgl() +
scale_fill_statgl(reverse = TRUE) +
labs(
title = sdg3$figs$fig21$title[language],
subtitle = sdg3$figs$fig21$sub[language],
x = " ",
y = sdg3$figs$fig21$y_lab[language],
fill = " ",
caption = sdg3$figs$fig21$cap[language]
)
# Import
SOXPV003_raw <-
statgl_url("SOXPV003", lang = language) |>
statgl_fetch(
"first adress in greenland" = px_all(),
year = px_top(3),
.col_code = TRUE
) |>
as_tibble()
# Transform
SOXPV003 <-
SOXPV003_raw |>
filter(`first adress in greenland` != SOXPV003_raw[[1]][1]) |>
mutate(
year = year |> as.numeric(),
`first adress in greenland` = `first adress in greenland` |> fct_reorder(value, sum)
)
# Plot
SOXPV003 |>
ggplot(aes(
x = `first adress in greenland`,
y = value,
fill = year
)) +
geom_col() +
coord_flip() +
theme_statgl() +
scale_color_statgl() +
theme(legend.position = "none") +
facet_wrap(~ year) +
labs(
title = statgl_meta(statgl_url("SOXPV003", lang = language))[1],
x = statgl_meta(statgl_url("SOXPV003", lang = language))[2]$variables[[1]]$text |> str_to_title(),
y = sdg3$figs$fig22$y_lab[language],
caption = sdg3$figs$fig22$cap[language]
)
# Import
SOXPV001_raw <-
statgl_url("SOXPV001", lang = language) |>
statgl_fetch(
unit = c("Aarsvaerk"),
"age of the child" = 0:19,
year = px_top(3),
.col_code = TRUE
) |>
as_tibble()
# Transform
SOXPV001 <-
SOXPV001_raw |>
mutate(
year = year |> as.numeric(),
`age of the child` = `age of the child` |> factor(levels = unique(`age of the child`))
)
# Plot
SOXPV001 |>
ggplot(aes(
x = `age of the child`,
y = value,
fill = year
)) +
geom_col() +
facet_wrap(~ year) +
coord_flip() +
theme_statgl() +
scale_color_statgl() +
theme(legend.position = "none") +
labs(
title = statgl_meta(statgl_url("SOXPV001", lang = language))[1],
subtitle = str_to_sentence(SOXPV001_raw[[1]][1]),
x = str_to_sentence(statgl_meta(statgl_url("SOXPV001", lang = language))[2]$variables[[2]]$text),
y = sdg3$figs$fig23$y_lab[language],
caption = sdg3$figs$fig23$cap[language]
)
diag_cat <-
c(
'F00: Uspec. fysisk handicap',
'F01: Synstab',
'F02: Høretab',
'F03: Epilepsi',
'F04: Stofskifte',
'F05: Andre progressive lidelser',
'F06: Gigt',
'F07: Genetiske & medfødte',
'F08: Indre organer',
'F09: Hudlidelse,vansiring',
'F10: Åndedræt',
'F11: Kredsløb',
'F12: Bevægeapparat',
'F13: Hjerneskade',
'F14: Immunforsvar',
'F15: Andre handicaps',
'F16: Talehandicap',
'P00: Uspec. psykisk handicap',
'P01: Mental retardering',
'P02: Organiske psykiske lidelser',
'P03: Misbrug',
'P04: Udviklingsforstyrrelse',
'P05: Personlighedsforstyrrelse',
'P06: Psykotiske lidelser',
'P07: Andre psykiske lidelser'
)
SOXFO11_raw <-
statgl_url("SOXFO11", lang = language) |>
statgl_fetch(
time = px_all(),
"diagnosis Category" = diag_cat,
.col_code = TRUE
) |>
as_tibble()
if (language == "da") {
f <- "Fysisk handicap"
p <- "Psykisk handicap"
} else if (language == "kl") {
f <- "Timikkut innarluuteqarneq"
p <- "Tarnikkut innarluuteqarneq"
} else {
f <- "Physical disability"
p <- "Mental disability"
}
vec <- c("F", "P")
names(vec) <- c(f, p)
SOXFO11 <-
SOXFO11_raw |>
separate(`diagnosis Category`, into = c("type", "cat")) |>
select(-cat) |>
mutate(type = type |> str_remove_all("[:digit:]")) |>
group_by(type, time) |>
summarise(value = sum(value, na.rm = TRUE)) |>
ungroup() |>
spread(type, value) |>
rename(vec) |>
gather(key, value, -time) |>
mutate(key = key |> fct_reorder(value, .fun = sum, .desc = FALSE))
SOXFO11 |>
ggplot(aes(
x = time,
y = value,
fill = key
)) +
geom_col() +
theme_statgl() +
scale_fill_statgl() +
labs(
title = sdg3$figs$fig24$title[language],
subtitle = sdg3$figs$fig24$sub[language],
y = " ",
x = " ",
fill = " ",
caption = sdg3$figs$fig24$cap[language]
)
url <- paste0("https://bank.stat.gl:443/api/v1/", language, "/Greenland/SU/SU01/SU0120/SUXLSKS1.px")
# Import
SUXLSKS1_raw <-
url |>
statgl_fetch(
age = 15:24,
disease = 1:3,
sex = px_all(),
time = px_top(5),
.col_code = T
) |>
as_tibble()
# Transform
SUXLSKS1 <-
SUXLSKS1_raw |>
group_by(disease, sex, time) |>
summarise(value = sum(value)) |>
ungroup() |>
arrange(disease, time) |>
unite(combi, disease, sex, sep = " ") |>
mutate(combi = fct_inorder(combi))
# Plot
SUXLSKS1 |>
ggplot() +
geom_col(aes(
x = time,
y = value,
fill = combi
),
position = "dodge"
) +
scale_fill_statgl(guide = guide_legend(ncol = 3)) +
theme_statgl() +
labs(
title = sdg3$figs$fig25$title[language],
subtitle = sdg3$figs$fig25$sub[language],
x = " ",
y = " ",
fill = " ",
caption = sdg3$figs$fig25$cap[language]
)