Skip to content

Instantly share code, notes, and snippets.

@sbfnk
Last active April 27, 2020 15:50
Show Gist options
  • Save sbfnk/7d10753608ae0d2b9b98db05960e6071 to your computer and use it in GitHub Desktop.
Save sbfnk/7d10753608ae0d2b9b98db05960e6071 to your computer and use it in GitHub Desktop.
google vs. rt
library("tidyverse")
library("ggplot2")
library("cowplot")
## get mobility data
dm <- read_csv("https://www.gstatic.com/covid19/mobility/Global_Mobility_Report.csv") %>%
mutate(date = as.Date(date, format = "%d/%m/%Y")) %>%
filter(is.na(sub_region_1)) %>%
rename(country = country_region) %>%
gather(type, value, 6:ncol(.)) %>%
mutate(type = sub("_percent.*$", "", type),
type = stringi::stri_trans_totitle(gsub("_", " ", type)))
## get reproduction numers
rt <- read_csv("https://raw.githubusercontent.com/epiforecasts/covid-global/37c8b2a94618681c280f55f581b4e83663ca130c/national-summary/rt.csv") %>%
left_join(dm, by = c("country", "date"))
ggplot(rt, aes(x = median, y = value, colour = type, fill = type)) +
geom_jitter(alpha=0.1) +
geom_smooth() +
xlab("R") + ylab("Mobility") +
cowplot::theme_cowplot() +
coord_cartesian(ylim = c(-100, 100)) +
expand_limits(x = 0) +
scale_color_brewer("", palette = "Dark2") +
scale_fill_brewer("", palette = "Dark2") +
theme(legend.position = "bottom")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment