knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.width = 8, fig.height = 5
)
# Load the packages needed to fetch and plot the COVID-19 data
library(COVIDutilities)
library(ggplot2)
library(magrittr)
library(dplyr)
library(scales)

Introduction

This vignette provides best practices for fetching COVID-19 vaccine data from Our World in Data Github repo.

We have updated COVIDutilities package with functionality to download vaccine data. Two new functions drive the process.

# The function below fetches a list of countries for which vaccine data is available
get_vax_countries() %>% head(15)

# Save the list of countries with data to an object name df_cntry
cntry_list <- get_vax_countries()

cat(paste("\n", "Number of countries with vaccine data available: ", length(cntry_list)))

With a valid list of countries, we can turn our attention to extracting a data frame with the actual vaccine data. To accomplish this we will make use of the get_vax_data() function. The function requires a character object

# Fetch all vaccine data (takes a bit to run)
df_vax <- get_vax_data(cntry_list)

glimpse(df_vax)

In some circumstances you may not need every country available. To extract a number of PEPFAR countries you can pass an object list of the country name.

df_vax_pepfar <- get_vax_data(paste(c("Zambia", "Nigeria", "South Africa", "Malawi", "Mozambique", "Zimbabwe", "Botswana", "United States"), "csv", sep = "."))
glimpse(df_vax_pepfar)

We can plot the data it to get a sense of what is going on in each country.

df_vax_pepfar %>% 
  ggplot(aes(x = date)) +
  geom_area(aes(y = people_vaccinated), fill = "#7ecfc0") +
  geom_area(aes(y = people_fully_vaccinated), fill = "#287c6f") +
  scale_y_continuous(labels = label_number_si()) +
    facet_wrap(~countryname, scales = "free_y") +
  coord_cartesian(expand = F) +
  labs(x = "", y ="", title = "Vaccination summary",
       caption = "Source: Our World In Data COVID-19 Vaccine data") +
  theme_minimal() +
  theme(panel.spacing = unit(0.5, "lines"))


USAID-OHA-SI/COVIDutilities documentation built on Aug. 18, 2022, 2:28 a.m.