@@ -20,7 +20,7 @@ om antallet af danskere i ordinær beskæftigelse, for hele landet, i 2023, ford
2020
2121``` {r}
2222library(tidyverse)
23- data <- read_csv2("https://api.statbank.dk/v1/data/AMR1/CSV?OMR%C3%85DE=000&KOEN=M %2CK&ALDER1=*&Tid=2023&SOCIO=021")
23+ data <- read_csv2("https://api.statbank.dk/v1/data/AMR1/CSV?OMR%C3%85DE=000&KOEN=* %2CK&ALDER1=*&Tid=2023&SOCIO=021")
2424head(data)
2525```
2626
@@ -49,7 +49,14 @@ det kan vi godt gøre pænere:
4949# fordi vi skal have en font der kan vise de to kønssymboler og procent med
5050# "normal" fonttykkelse.
5151library(showtext)
52- font_add("seguisym", "SEGUISYM.TTF")
52+ # Først skal vi have styr på hvor font-filen faktisk ligger.
53+ if (requireNamespace("rstudioapi", quietly = TRUE) && rstudioapi::isAvailable()) {
54+ script_dir <- dirname(rstudioapi::getActiveDocumentContext()$path)
55+ } else {
56+ script_dir <- dirname(normalizePath(sys.frame(1)$ofile))
57+ }
58+
59+ font_add("seguisym", file.path(script_dir, "SEGUISYM.TTF"))
5360showtext_auto()
5461
5562
@@ -70,8 +77,33 @@ tot_data |>
7077 subtitle = "2023",
7178 caption = "Danmarks Statistik, Statistikbanken, AMR1") +
7279 coord_polar("y", start = 0) +
73- scale_fill_manual(values = c("Kvinder" = "red", "Mænd" = "blue"), guide = "none")
74-
80+ scale_fill_manual(values = c("Kvinder" = "red", "Mænd" = "blue"), guide = "none") +
81+ theme_void()
82+ ```
83+
84+ ``` {r}
85+ data |>
86+ group_by(ALDER1) |>
87+ # filter(ALDER1 == "16-19 år") |>
88+ mutate(andel = INDHOLD/sum(INDHOLD),
89+ label = if_else(KOEN == "Kvinder","\u2640", "\u2642" )) |>
90+ ungroup() |>
91+ ggplot(aes(x="", y = andel, fill = KOEN)) +
92+ geom_bar(stat = "identity", width = 1, color = "black") +
93+ coord_polar("y", start = 0) +
94+ facet_wrap(~ALDER1) +
95+ geom_text(aes(label = glue("{label} \n {scales::percent(andel, accuracy = 1)}")) ,
96+ position = position_stack(vjust = 0.5),
97+ size = 2 ,
98+ family = "seguisym",
99+ color = "black") +
100+
101+ labs(title = "Fordeling af ordinært fuldtidsbeskæftigede",
102+ subtitle = "2023",
103+ caption = "Danmarks Statistik, Statistikbanken, AMR1") +
104+ coord_polar("y", start = 0) +
105+ scale_fill_manual(values = c("Kvinder" = "red", "Mænd" = "blue"), guide = "none") +
106+ theme_void()
75107```
76108
77109
0 commit comments