Add data comparison mapping
This commit is contained in:
32
global.R
32
global.R
@@ -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]]
|
||||
|
||||
Reference in New Issue
Block a user