TEST kohorte
TEST: Hvor mange fra en fødselsårgang bor i Grønland over tid
TEST: Hvor mange fra en fødselsårgang bor i Grønland over tid
29.05.2026
---
title: TEST kohorte
subtitle: "TEST: Hvor mange fra en fødselsårgang bor i Grønland over tid"
order: 2.6
tag:
- pop_size
toc: true
toc-title: Kohorte
icon: bi-hourglass-split
lang: da
date: last-modified
date-format: "DD.MM.YYYY"
execute:
echo: false
warning: false
---
```{r}
library(tidyverse)
library(jsonlite)
library(statgl)
library(highcharter)
```
```{r}
df_1 <-
statgl_fetch(
"BEDSTFSGRL",
cohort = 1925:2025,
status = "*",
time = px_all(),
.col_code = TRUE
) |>
mutate(
time = as.numeric(time),
cohort_label = as.character(cohort),
status_label = as.character(status)
)
df_1 <- df_1 |>
mutate(
cohort = as.character(cohort),
time = as.numeric(time)
) |>
arrange(desc(as.integer(cohort)), status, time)
cohorts <- df_1 |>
distinct(cohort) |>
arrange(desc(as.integer(cohort))) |>
pull(cohort)
```
{{< filter
id="cohort"
label="Min fødselsårgang"
options='`r toJSON(cohorts)`'
multiple=false
>}}
```{r linje, eval=FALSE}
p <- df_1 |>
mutate(
cohort_filter = cohort,
series_id = paste(cohort_filter, status, sep = "__")
) |>
arrange(desc(as.integer(cohort)), status, time) |>
statgl_plot(
x = time,
y = value,
group = series_id,
digits = 0,
suffix = " personer",
series_tags = list(cohort = "cohort_filter"),
legend_position = "none"
)
for (i in seq_along(p$x$hc_opts$series)) {
old_name <- p$x$hc_opts$series[[i]]$name
cohort_i <- sub("__.*$", "", old_name)
status_i <- sub("^.*__", "", old_name)
p$x$hc_opts$series[[i]]$name <- cohort_i
n <- length(p$x$hc_opts$series[[i]]$data)
for (j in seq_len(n)) {
p$x$hc_opts$series[[i]]$data[[j]]$dataLabels <- list(enabled = FALSE)
}
p$x$hc_opts$series[[i]]$data[[n]]$dataLabels <- list(
enabled = TRUE,
format = paste0(status_i, " {y:.0f} personer")
)
}
```
```{r area}
p <- df_1 |>
mutate(
cohort_filter = cohort,
series_id = paste(cohort_filter, status, sep = "__")
) |>
arrange(desc(as.integer(cohort)), status, time) |>
statgl_plot(
x = time,
y = value,
group = series_id,
type = "area",
digits = 0,
suffix = " personer",
series_tags = list(cohort = "cohort_filter"),
legend_position = "none"
) |>
hc_plotOptions(
area = list(
stacking = "normal",
marker = list(enabled = FALSE)
)
) |>
hc_legend(enabled = FALSE)
status_colors <- c(
"Grønland" = "#008c95",
"Danmark" = "#f2c94c",
"Udrest" = "#9b51e0",
"Død" = "#bdbdbd"
)
for (i in seq_along(p$x$hc_opts$series)) {
old_name <- p$x$hc_opts$series[[i]]$name
cohort_i <- sub("__.*$", "", old_name)
status_i <- sub("^.*__", "", old_name)
p$x$hc_opts$series[[i]]$custom <- list(
cohort = cohort_i,
status = status_i
)
if (status_i %in% names(status_colors)) {
p$x$hc_opts$series[[i]]$color <- status_colors[[status_i]]
p$x$hc_opts$series[[i]]$fillColor <- status_colors[[status_i]]
}
p$x$hc_opts$series[[i]]$name <- status_i
n <- length(p$x$hc_opts$series[[i]]$data)
for (j in seq_len(n)) {
p$x$hc_opts$series[[i]]$data[[j]]$dataLabels <- list(enabled = FALSE)
}
p$x$hc_opts$series[[i]]$data[[n]]$dataLabels <- list(
enabled = TRUE,
format = paste0(status_i, " {y:.0f} personer")
)
}
```
{{< shorty
plot = '`r p`'
filter_series = "cohort"
>}}
```{=html}
<script>
document.addEventListener("DOMContentLoaded", function () {
const defaultCohort = "1968";
const select = document.querySelector(
'[data-filter-id="cohort"], select#cohort, select[name="cohort"]'
);
if (select) {
select.value = defaultCohort;
select.dispatchEvent(new Event("change", { bubbles: true }));
}
});
</script>
```