Add data comparison mapping

This commit is contained in:
2026-01-07 22:08:50 +01:00
parent edb880b9b8
commit f5c0c94e77

View File

@@ -55,6 +55,38 @@ map_data_to_top3_plot <- function(bezirk, stadtteil, year) {
return(top_3_tibble)
}
map_data_to_plot <- function(locations, crimes, year) {
year <- as.character(trimws(year))
req(locations)
req(crimes)
req(year)
return(map_df(locations, function(loc) {
bezirk <- ""
stadtteil <- ""
if (substring(loc, 0, 6) == "Bezirk") {
bezirk <- substring(loc, 7)
stadtteil <- loc
}
else {
bezirk <- get_bezirk_by_stadtteil(loc)
stadtteil <- loc
}
komplettes_tibble <- map_df(crimes, function(crime) {
row <- crime_json[[bezirk]][[stadtteil]][[crime]][[year]]
tibble(
Name = str_wrap(crime, width = 25),
Erfasst = as.integer(row[["Erfasste Fälle"]]),
Location = loc
)
})
}) %>%
arrange(desc(Erfasst))
)
}
get_intensity_df <- function(crime_json, delikt, jahr = "2024", feld = "Erfasste Fälle") {
do.call(rbind, lapply(names(crime_json), function(bezirk) {
stadtteile <- crime_json[[bezirk]]