knitr::opts_chunk$set(echo = TRUE)
Load required packages.
anim <- require(gganimate) library(dplyr) library(ggplot2) library(ggthemes) library(maps) library(tdor)
[TRIGGER WARNING: VIOLENCE. MURDER]
The data can be explored through this website: [https://tdor.translivesmatter.info/]
ggplot(tdor, aes(Year)) + geom_bar() + ggtitle("Deaths by year")
In some cases there is ambiguity over the age, so we have a minimum and a maximum.
tdor %>% filter(`Age min` > 0 & `Age max` > 0) %>% ggplot(aes(x = (`Age min` + `Age max`)/2)) + geom_bar() + ggtitle("Deaths by age") + labs(y = "Deaths") tdor %>% filter(`Age min` > 0 & `Age max` > 0) %>% ggplot(aes(x = (`Age min` + `Age max`)/2)) + geom_histogram(binwidth = 5) + ggtitle("Deaths by age") + labs(y = "Deaths")
tdor %>% group_by(Country) %>% summarise(n = n()) %>% arrange(desc(n)) -> by_country ggplot(by_country[1:10,], aes(x = Country, y = n)) + theme_bw() + labs(y = "Deaths", x = "") + geom_bar(stat="identity") + theme(axis.text.x = element_text(angle=45, hjust=1)) + ggtitle("Ten countries with the most reported deaths")
world <- ggplot() + borders("world", colour = "gray85", fill = "gray80") + theme_map() map <- world + geom_point(aes(x = Longitude, y = Latitude), data = tdor, colour = 'purple', alpha = .2) + ggtitle("Map of deaths (2006-2018)") map
Animate by name
if (anim){ d18 <- filter(tdor, Year == 2018) map_anim_name <- world + geom_point(aes(x = Longitude, y = Latitude), data = d18, colour = 'red', alpha = .5) + labs(title = paste('{closest_state}', "died here")) + transition_states( Name, transition_length = 1, state_length = 1) + shadow_mark() # to get full animation... animate(map_anim_name, nframes = nrow(d18)*2) animate(map_anim_name, nframes = nrow(d18)*2) + anim_save(filename = 'world_map_names.gif') }
tdor %>% select(Date) %>% mutate(month=lubridate::floor_date(Date, unit = "1 month")) %>% count(month) %>% right_join( seq.Date(from = as.Date("2006-10-01"), to=as.Date("2018-09-01"), , by="month") %>% as_tibble() %>% select(month=value) ) %>% ggplot()+ aes(x=month, y=n)+ geom_line()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.