Testing Google Mobility Data

7/2/2020

Libraries

library(ggplot2)
library(dplyr)
library(magrittr)
library(tidyr)

Load data

Data is here:https://www.google.com/covid19/mobility/. It is available for about 20 African countries. And it is regionally disaggregated for many of them as well (Nigeria, Kenya, Mozambique, Togo, Tanzania). So we could include the charts on the regional data pages.

mob <- read.csv('/Users/kenwosu/Desktop/WHO AFRO/Global_Mobility_Report.csv')

Clean and Reshape

#ghana only
ghana <- filter(mob, country_region== "Ghana")

#simpler names
names(ghana) <- c("code","country","region1","region2","isocode","censuscode", "date",
                  "retail and recreational areas", "groceries and pharmacies", "parks", "transit stations",
                  "workplaces", "residential areas")

#delete useless vars
ghana <- ghana[,7:13]

#reshape
ghanalong <- pivot_longer(ghana, cols = c("retail and recreational areas", "groceries and pharmacies", "parks", "transit stations", "workplaces", "residential areas"))

Plot

#filter and plot
ghanalong$date <- as.Date(ghanalong$date)
ghanalong %>% 
  filter(name %in% c("retail and recreational areas","groceries and pharmacies",
                     "workplaces", "residential areas")) %>% 
  ggplot() +
  geom_line(aes(x=date, y=value, color = name)) +
  labs(y="% change from baseline", x="", title="Mobility Changes in Ghana" ) +
  scale_x_date(date_labels = "%b %d") +
  theme(legend.title = element_blank(),
        legend.position = "bottom",
        panel.background = element_rect(fill = "transparent"),
        title = element_text(face = "bold"),
        plot.background = element_rect(fill = "transparent"),
        panel.grid.major = element_line(color = alpha("gray50", 0.2), size = 0.5),
        panel.grid.major.x = element_blank(),
        axis.line = element_line(color = "gray40", size = 0.5),
        axis.line.y = element_blank())

Compare with epicurves?

We could put these side by side with the epicurves, or layer them on top the epicurves, to get a sense of the relationship.

And perhaps manually add in important dates with geom_segment.

plotting events on epicurve