Skip to content

Instantly share code, notes, and snippets.

@mrjoh3
Created July 18, 2018 12:42
Show Gist options
  • Save mrjoh3/2b53df32f864199e5ef89324d1c4170f to your computer and use it in GitHub Desktop.
Save mrjoh3/2b53df32f864199e5ef89324d1c4170f to your computer and use it in GitHub Desktop.
Animation of alcohol related related road accidents in Victoria Australia 2012 - 2017
library(dplyr)
library(sf)
library(ggplot2)
library(gganimate)
shp <- st_read('shp','Crashes_Last_Five_Years') %>%
filter(ALCOHOL_RE == 'Yes') %>%
mutate(date = as.Date(as.character(ACCIDENT_D), '%d/%m/%Y'))
vic <- st_read('shp', 'VIC_STATE_POLYGON_shp')
ggplot() +
geom_sf(data = vic, fill = 'grey', colour = 'darkgrey') +
geom_sf(data = shp, aes(colour = SEVERITY)) +
scale_color_manual(values = c('red', 'orange' ,'yellow')) +
guides(colour = guide_legend('')) +
theme(axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank(),
axis.title.y=element_blank(),
axis.text.y=element_blank(),
axis.ticks.y=element_blank(),
panel.background = element_rect(fill = "darkgrey", colour = "darkgrey"),
plot.background = element_rect(fill = "darkgrey"),
legend.position = "bottom",
legend.background = element_rect(fill = "darkgrey"),
legend.key = element_rect(fill = "darkgrey", colour = "darkgrey")) +
labs(title = 'Alcohol Related Daily Road Accidents in Victoria 2012-2017',
subtitle = 'Date: {frame_time}') +
transition_time(date) +
ease_aes('linear')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment