# 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 = "Aborter", x = "Tid", y = "Aborter pr. 1000 kvinder i alderen 12-49 år\n(Aldersstandardiseret)",
subtitle = "Aldersstandardiseret - Baseår 2000")
# Import
BEXDT5A_raw <-
statgl_url("BEXDT5A", lang = "da") %>%
statgl_fetch(type = "E",
age = c(0, 1),
.col_code = TRUE) %>%
as_tibble()
# Transform
BEXDT5A <-
BEXDT5A_raw %>%
separate(time, into = c("startaar", "slutaar"), sep = " - ") %>%
mutate(slutaar = slutaar %>% as.numeric %>% make_date()) %>%
select(-3)
# Plot
BEXDT5A %>%
ggplot(aes(x = slutaar, y = value, color = age)) +
geom_line(size = 2) +
scale_y_continuous(labels = scales::unit_format(
suffix = " ",
big.mark = ".",
decimal.mark = ","
)) +
theme_statgl() + scale_color_statgl() +
labs(
title = "Middellevetid for 0 og 1-årige",
subtitle = "Personer født i Grønland",
x = "Tid (5-års-intervaller)",
y = "Middellevetid",
color = "Alder",
caption = "Kilde: https://bank.stat.gl/BEDDT5A"
)
# Import
BEXDT5A_raw <-
statgl_url("BEXDT5A", lang = "da") %>%
statgl_fetch(type = "E",
age = c(0, 1),
residence = 1:2,
.col_code = TRUE) %>%
as_tibble()
# Transform
BEXDT5A <-
BEXDT5A_raw %>%
separate(time, into = c("startaar", "slutaar"), sep = " - ") %>%
mutate(slutaar = as.numeric(slutaar) %>% make_date()) %>%
select(-4)
# Plot
BEXDT5A %>%
ggplot(aes(
x = slutaar,
y = value,
color = age
)) +
geom_line(size = 2) +
facet_wrap(~ residence) +
scale_y_continuous(labels = scales::unit_format(
suffix = " ",
big.mark = ".",
decimal.mark = ","
)) +
theme_statgl() +
theme(plot.margin = margin(10, 10, 10, 10)) +
scale_color_statgl(reverse = TRUE,
guide = guide_legend(reverse = TRUE)) +
labs(
title = "Midellevetid for 0 og 1-årige efter bosted",
subtitle = "Personer født i Grønland",
x = "Tid (5-års-intervaller)",
y = "Middellevetid",
color = "Alder",
caption = "Kilde: https://bank.stat.gl/BEDDT5A"
)
# 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 = "Dødelighed", subtitle = "Aldersstandardiseret - Baseår 2000",
x = "Tid", y = "Aldersstandardiseret rate (pr. 1000)"
)
# 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(),
gender = c("M", "K"),
.col_code = TRUE) %>%
as_tibble() %>%
rename(c("alder" = 1,
"art" = 2,
"køn" = 3,
"tid" = 4,
"Dødsfald" = 5))
BEDBBDM1 <- BEDBBDM1_raw %>% as_tibble() %>% spread(art, Dødsfald) %>%
mutate_at(c(1, 3), strtoi)
BEDBBDM1_2000 <- BEDBBDM1 %>% arrange(tid, køn, alder) %>% filter(tid == 2000) %>% pull(Middelfolketal)
BEDBBDM1_std <- BEDBBDM1 %>% group_by(tid, køn) %>% arrange(alder) %>%
summarise(age_adjust(Døde, Middelfolketal, stdpop = BEDBBDM1_2000) * 1000) %>%
ungroup()
BEDBBDM1_std %>%
ggplot(aes(
x = tid,
y = std_rate,
color = køn
)) +
geom_line(size = 2) +
theme_statgl() +
scale_color_statgl(reverse = TRUE) +
labs(
title = "Dødelighedsrate efter køn",
subtitle = "Aldersstandardiseret - Baseår 2000",
color = "",
x = "Tid",
y = "Aldersstandardiseret rate (pr.1000)"
)
# Import
TUB01_raw <- read_csv(
"http://pxweb.fujitsu.dk/sq/1417044b-c578-4c3a-a97d-5056b117ad52",
locale = locale(encoding = "latin1")) %>%
as_tibble()
# Transform
TUB01 <-
TUB01_raw %>%
spread(sex, Greenland) %>%
rename(Mænd = Men,
Kvinder = Women) %>%
gather(køn, tb, -year) %>%
mutate(year = year %>% make_date())
# Plot
TUB01 %>%
ggplot(aes(x = year, y = tb, color = køn)) +
geom_line(size = 2) +
expand_limits(y = 0) +
theme_statgl() + scale_color_statgl(reverse = TRUE) +
labs(
title = "Diagnostiserede tilfælde af tuberkulose",
subtitle = "Antal tilfælde per hundredetusinde personer",
x = " ",
y = "Tilfælde per hundredetusinde personer",
color = " ",
caption = "Kilde: Nordic Health and Social Statistics, tabel TUB01"
)