Last active
May 11, 2019 13:26
-
-
Save mschnetzer/4b442e7bf96edec7abdec5806c68a4e5 to your computer and use it in GitHub Desktop.
Firearm deaths in the United States 1999-2017 (https://twitter.com/matschnetzer/status/1119168161373413381)
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(grid) | |
library(png) | |
library(msthemes) | |
library(gganimate) | |
gun <- readPNG("gun.png") | |
# Download data from https://wonder.cdc.gov/controller/saved/D76/D48F344 | |
gundf <- read.table(file = "Firearm deaths by intent, 1999-2017.txt", header = T, fill=T, sep="\t") %>% filter(Notes=="Total", !is.na(Year)) %>% select(Year,Deaths) | |
gunplot <- gundf %>% ggplot(aes(x=Year,y=Deaths)) + | |
geom_line(size=1.7) + | |
geom_point(size=3, color="gold") + | |
scale_y_continuous(position = "right", limits = c(20000,40000)) + | |
scale_x_continuous(limits = c(1995,2017), breaks = seq(2000,2015,5)) + | |
theme_ms() + | |
annotation_custom(rasterGrob(gun, | |
x=0,y=0.11, | |
width = unit(0.5,"npc"))) + | |
labs(x="",y="", title="Gun deaths in the US on highest level in 20 years", subtitle="Firearm deaths in the United States 1999-2017", caption="Source: CDC WONDER. Figure: @matschnetzer") + | |
transition_reveal(Year) | |
anim <- animate(gunplot, height=4, width=7, res=300, unit="in", end_pause = 20) | |
anim_save("gundeaths.gif", anim) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment