Skip to content

Instantly share code, notes, and snippets.

@diegovalle diegovalle/mx_geofacet.R
Last active May 4, 2019

Embed
What would you like to do?
Mexico geofacet
library(dplyr)
library(readr)
library(ggplot2)
library(geofacet)
read_csv("https://data.diegovalle.net/elcrimen/data/nm-estatal-victimas.csv.gz") %>%
filter(subtipo == "HOMICIDIO DOLOSO") %>%
group_by(subtipo, state_code, state, date) %>%
summarise(count = sum(count, na.rm = TRUE),
population = sum(population[1:8], na.rm = TRUE)) %>%
mutate(date = as.Date(paste0(date, "-01"))) %>%
mutate(rate = count / population * 10^5 * 12) %>%
mutate(code = as.integer(state_code)) %>%
ggplot(aes(date, rate)) +
geom_line() +
facet_geo(~ code, grid = mx_state_grid2, label = "name") +
ggtitle("Homicide rate in Mexico (Jan 2014 - June 2017)",
subtitle = "Data Source: https://elcri.men") +
ylab("annualized homicide rate") +
theme_bw()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.