Skip to content

Instantly share code, notes, and snippets.

@expersso
Last active June 19, 2018 09:08
Show Gist options
  • Save expersso/26ce15f5d14f91014dcd963ced385b29 to your computer and use it in GitHub Desktop.
Save expersso/26ce15f5d14f91014dcd963ced385b29 to your computer and use it in GitHub Desktop.
Dataframe of German Crime Statistics
# 1987-1990: old federal states (Bundesländer)
# 1991-1992: old federal states and Berlin metropolitan area
# from 1993: all federal states
library(tidyverse)
nms <- c("key", "crime", "year", "total", "per_100k_pre2013_census",
"per_100k_post2013_census", "attempts_total",
"attempts_share_of_total", "with_firearm_threat", "with_firearm_shot",
"percent_cases_solved", "total_suspects", "non_german_suspects",
"percent_share_non_german_suspects")
url <- paste0("https://www.bka.de/SharedDocs/Downloads/DE/Publikationen",
"/PolizeilicheKriminalstatistik/2017/Zeitreihen/Faelle/",
"ZR-F-01-T01-Faelle_csv.csv?__blob=publicationFile&v=3")
df <- read_delim(url, ";", skip = 1, na = "-",
locale = locale(encoding = "ISO-8859-1")) %>%
set_names(nms) %>%
mutate(per_100k = if_else(is.na(per_100k_post2013_census),
per_100k_pre2013_census,
per_100k_post2013_census))
crimes <- tribble(
~crime_english, ~crime,
"Total crimes", "Straftaten insgesamt",
"Crimes against life (e.g. murder)", "Straftaten gegen das Leben",
"Crimes against sexual autonomy (e.g. rape)", "Straftaten gegen die sexuelle Selbstbestimmung")
df %>%
filter(crime %in% crimes$crime, year >= 1993) %>%
left_join(crimes) %>%
ggplot(aes(x = year, y = per_100k)) +
geom_line() +
geom_point() +
facet_wrap(~crime_english, scales = "free_y") +
theme_light()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment