joachim-gassen / tidycovid19

{tidycovid19}: An R Package to Download, Tidy and Visualize Covid-19 Related Data
https://joachim-gassen.github.io/tidycovid19/
Other
146 stars 44 forks source link

Oxford data update #16

Closed guidopowell closed 4 years ago

guidopowell commented 4 years ago

Hi Joachim Really appreciate the work you are doing. Do you plan on updating the Oxford data to include their recent modifications? I have followed you discussion of the issue with their approach but still think it is valuable to compare sources https://www.bsg.ox.ac.uk/research/research-projects/coronavirus-government-response-tracker

Thanks Guido

joachim-gassen commented 4 years ago

Sorry for the delay - The modifications of the Oxford data are by now reflected in download_oxford_npi_data(). The new version allows you to either download the data organized by measures or the stringency index data by by country-day. E.g.:

library(tidyverse)
library(tidycovid19)
df <- download_oxford_npi_data(type = "index", cached = TRUE)

df %>% group_by(date) %>%
  summarise(
    mn_si = mean(stringency_index, na.rm = TRUE),
    ci_si =  1.96*(sd(stringency_index, na.rm = TRUE)/sqrt((n() - 1)))
  ) %>%
  ggplot(aes(x = date, y = mn_si)) +
  geom_line()  + 
  geom_errorbar(
    aes(
      ymin= mn_si - ci_si, 
      ymax = mn_si + ci_si
    ),
    width = 0.2
  ) 

df <- download_oxford_npi_data(type = "measures", cached = TRUE)

df %>% filter(
  npi_type != "Emergency investment in healthcare",
  npi_type != "Investment in vaccines",
  npi_measure != 0
) %>%
  ggplot(aes(x = date, fill = npi_type, weight = npi_measure)) +
  geom_histogram(position = "stack", binwidth = 7)