Created
October 24, 2020 08:00
-
-
Save mschnetzer/5dc621d5fe34f39137943b24494c5d0c to your computer and use it in GitHub Desktop.
Entwicklung der Covid-Pandemie in Österreichs Bezirken (https://twitter.com/matschnetzer/status/1319904508386942976)
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(sf) | |
library(gganimate) | |
library(transformr) | |
library(lubridate) | |
library(msthemes) # https://github.com/mschnetzer/msthemes | |
# Import online map | |
bezirke <- st_read("https://raw.githubusercontent.com/ginseng666/GeoJSON-TopoJSON-Austria/master/2017/simplified-99.9/bezirke_999_geo.json") %>% | |
mutate(iso = as.numeric(iso)) | |
# Download AGES Dashboard data @ https://covid19-dashboard.ages.at/ | |
covid <- read_csv2("data/CovidFaelle_Timeline_GKZ.csv") %>% | |
mutate(datum = ymd(dmy_hms(str_replace_all(Time,"\\.","-")))) %>% | |
mutate(AnzahlFaelle7Tage = replace_na(AnzahlFaelle7Tage, 0)) | |
# Combine map and data | |
mapdata <- bezirke %>% left_join(covid, by = c("iso" = "GKZ")) | |
# Plot and animate | |
anim <- mapdata %>% | |
ggplot() + | |
geom_sf(aes(fill = AnzahlFaelle7Tage/AnzEinwohner*100000), size = 0.3) + | |
scale_fill_gradientn(colours=c("green","yellow","orange","red","dark red"), | |
limits=c(0,150), na.value = "dark red", | |
labels = c("0", "50", "100", ">150")) + | |
guides(fill=guide_colourbar(title = NULL, | |
barwidth = 15, | |
barheight = .5)) + | |
theme_ms(grid = F, alttf = T) + | |
theme(legend.position = "bottom", | |
axis.text = element_blank()) + | |
labs(title = "Entwicklung der Covid-Fälle seit Februar 2020", | |
subtitle = "7-Tage-Inzidenz pro 100.000 Einwohner - Datum: {frame_time}", | |
caption = "Grafik: @matschnetzer") + | |
transition_time(datum) | |
gif <- animate(anim, nframes = length(unique(mapdata$datum)), end_pause = 30, res = 150, unit = "in", width = 6, height = 5) | |
anim_save("covid.gif", animation = gif) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment