knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
This is an R wrapper around the COVID Tracking Project API. It provides updates on the spread of the virus in the US with a few simple functions.
install.packages("covid19us")
Or the dev version:
devtools::install_github("aedobbyn/covid19us")
library(covid19us)
Get the most recent COVID-19 top-line data for the country:
get_us_current()
Or the same by state:
get_states_current()
Daily state counts can be filtered by state and/or date:
get_states_daily( state = "NY", date = "2020-03-17" )
For data in long format:
(dat <- refresh_covid19us())
Which can be easier to plot
library(dplyr) library(ggplot2) dat %>% filter( location == "NY" & data_type %in% c( "positive_increase", "total_test_results_increase", "death_increase", "hospitalized_increase" ) ) %>% mutate( Type = data_type %>% stringr::str_replace_all("_", " ") %>% stringr::str_to_title() ) %>% arrange(date) %>% ggplot(aes(date, value, color = Type)) + geom_smooth(se = FALSE) + scale_x_date(date_breaks = "2 weeks") + labs(title = "COVID in NY") + xlab("Date") + ylab("Value") + theme_minimal(base_family = "Source Sans Pro")
To get information about the data:
get_info_covid19us()
get_counties_info get_info_covid19us get_states_current get_states_daily get_states_info get_tracker_urls get_us_current get_us_daily refresh_covid19us
get_tracker_urls()
The filter
column gives information about how the COVID Tracking Project's scraper currently scrapes data from the page (xpaths, CSS selectors, functions used, etc.)
State breakdowns include DC as well as some US territories including American Samoa (AS), Guam (GU), Northern Mariana Islands (MP), Puerto Rico (PR), and the Virgin Islands (VI)
Acronyms
PUM: persons under monitoring (one step before PUI)
Time zone used is Eastern Standard Time
PRs and bug reports / feature requests welcome. Stay safe!
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.