Created
November 16, 2022 15:57
-
-
Save benzipperer/2fefdafcd522351f385a58688c82e5f1 to your computer and use it in GitHub Desktop.
plot time series of US K-12 shootings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(lubridate) | |
library(hrbrthemes) | |
# K-12 shooting incident data from https://www.chds.us/ssdb/data-map/ | |
readxl::read_excel("SSDB_Raw_Data.xlsx", sheet = "INCIDENT") %>% | |
mutate( | |
year = year(ymd(Date)), | |
month = month(ymd(Date)), | |
month_date = ym(paste(year, month)) | |
) %>% | |
group_by(month_date) %>% | |
count() %>% | |
ungroup() %>% | |
mutate(n = slider::slide_dbl(n, sum, .before = 11, .complete = TRUE)) %>% | |
ggplot(aes(x = month_date, y = n)) + | |
geom_line() + | |
labs( | |
title = "Number of shootings at K-12 schools over the past 12 months", | |
x = NULL, | |
y = NULL, | |
caption = "Source: 12-month sum of Center for Homeland Defense and Security School Shooting Safety Compendium data. \nAnalysis by Ben Zipperer at https://gist.github.com/" | |
) + | |
theme_ipsum_rc(base_size = 14) + | |
theme( | |
plot.margin = margin(20,20,10,20), | |
plot.title = element_text(size = 25), | |
plot.caption = element_text(size = 11) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment