knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

covdata

R build status

About the package

covdata is a data package for R that collects and bundles datasets related to the COVID-19 pandemic from a variety of sources. The data are current as of r format(Sys.Date(), "%A, %B %e, %Y"). Minimal post-processing of the data has been done in comparison to the original sources, beyond conversion to tibbles and transformation into narrow- or tidy form. Occasionally some additional variables have been added (mostly ISO country codes) to facilitate comparison across the datasets or their integration with other sources.

covdata provides the following:

COVID-19 specific case and mortality data

All-cause mortality and excess mortality data

Mobility and activity data

Caveat Emptor

The data are provided as-is. More information about collection methods, scope, limits, and possible sources of error in the data can be found in the documentation provided by their respective sources. Follow the links above, and see the vignettes in the package. The collection and effective reporting of case and mortality data by national governments has technical and political aspects influenced by, amongst other things, the varying capacity of states to test, track and measure events in a timely fashion, the varying definitions, criteria, and methods employed by states in registering cases and deaths, and the role of politics in the exercise of capacity and the reporting of unflattering news. Researchers should take care to familiarize themselves with these issues prior to making strong claims based on these data.

Installation

There are two ways to install the covdata package.

Install direct from GitHub

You can install covdata from GitHub with:

remotes::install_github("kjhealy/covdata@main")

Installation using drat

While using install_github() works just fine, it would be nicer to be able to just type install.packages("covdata") or update.packages("covdata") in the ordinary way. We can do this using Dirk Eddelbuettel's drat package. Drat provides a convenient way to make R aware of package repositories other than CRAN.

First, install drat:

if (!require("drat")) {
    install.packages("drat")
    library("drat")
}

Then use drat to tell R about the repository where covdata is hosted:

drat::addRepo("kjhealy")

You can now install covdata in the usual way:

install.packages("covdata")

To ensure that the covdata repository is always available, you can add the following line to your .Rprofile or .Rprofile.site file:

drat::addRepo("kjhealy")

With that in place you'll be able to do install.packages("covdata") or update.packages("covdata") and have everything work as you'd expect.

Note that my drat repository only contains data packages that are not on CRAN, so you will never be in danger of grabbing the wrong version of any other package.

Loading the Data

library(tidyverse) # Optional but strongly recommended
library(covdata)

covnat_weekly
apple_mobility %>%
  filter(subregion_and_city == "New York City", transportation_type == "walking")
covus %>%
  filter(measure == "positive", 
         date == "2020-04-27", 
         state == "NJ")
nytcovcounty %>%
  mutate(uniq_name = paste(county, state)) %>% # Can't use FIPS because of how the NYT bundled cities
  group_by(uniq_name) %>%
  mutate(days_elapsed = date - min(date)) %>%
  ggplot(aes(x = days_elapsed, y = cases, group = uniq_name)) + 
  geom_line(size = 0.25, color = "gray20") + 
  scale_y_log10(labels = scales::label_number_si()) + 
  guides(color = FALSE) + 
  facet_wrap(~ state, ncol = 5) + 
  labs(title = "COVID-19 Cumulative Recorded Cases by US County",
       subtitle = paste("New York is bundled into a single area in this data.\nData as of", format(max(nytcovcounty$date), "%A, %B %e, %Y")),
       x = "Days since first case", y = "Count of Cases (log 10 scale)", 
       caption = "Data: The New York Times | Graph: @kjhealy") + 
  theme_minimal()

Documentation and Summary Codebook

To learn more about the different datasets available, consult the vignettes or, equivalently, the package website. For a codebook-like summary of the variables in each table, see the Codebook vignette

Citing the covdata package

To cite the package use the following:

citation("covdata")

Please be sure to also cite the specific data sources, as described in the documentation for each dataset.

Mask icon in hex logo by Freepik.



kjhealy/covdata documentation built on Feb. 4, 2023, 12:52 p.m.