Created
May 27, 2020 20:54
-
-
Save jebyrnes/8122b7f01c13aa43f19ec700eeeb5d8c to your computer and use it in GitHub Desktop.
Google Mobility on world tile map
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
#devtools::install_github("hrbrmstr/worldtilegrid") | |
library(worldtilegrid) | |
library(dplyr) | |
library(ggplot2) | |
goog <- refresh_covid19mobility_google_country() | |
data(wtg) | |
goog_april <- filter(goog, | |
as.character(date) %in% c("2020-04-15", "2020-02-15", "2020-03-15", "2020-05-15"), | |
data_type=="retail_and_recreation_percent_change_from_baseline") %>% | |
filter(!is.na(date)) | |
wtg_toplot <- left_join(wtg, | |
goog_april, | |
by = c("alpha.2" = "location_code")) %>% | |
mutate(color = "white", | |
color = ifelse(value < -25 | is.na(value), color, "black")) %>% | |
filter(!is.na(date)) | |
ggplot(wtg_toplot, | |
aes(country = name, fill = value)) + | |
geom_wtg(border_size = 0.5, border_col = "#252a32") + | |
scale_fill_viridis_c(labels = scales::percent_format(scale = 1)) + | |
coord_equal() + | |
facet_wrap(~date) + | |
# geom_text( | |
# aes( | |
# label = alpha.2, color = I(color)), | |
# #color = "white", | |
# stat = "wtg", | |
# size = 2 | |
# ) + | |
theme_void(base_size=16) + | |
labs(title = "Retail and Recreation Change from Baseline", | |
subtitle = "Data from Google Mobility Reports\n", | |
fill = "", | |
caption = "Data source: https://www.google.com/covid19/mobility/\n") + | |
#hrbrthemes::theme_ft_rc(grid="") + | |
#theme(axis.text=element_blank()) + | |
theme(legend.position = "bottom", | |
plot.caption = element_text(hjust = 1.5), | |
legend.key.width = unit(2, "cm")) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment