Learn R Programming

covid19nytimes

The covid19nytimes package harvests the data made freely available by the New York Times. See https://www.nytimes.com/article/coronavirus-county-data-us.html for more.

Installation

You can install the released version of covid19nytimes from CRAN with:

install.packages("covid19nytimes")

Or the latest development version from github

devtools::install_github("covid19R/covid19nytimes")

Data

The package has the data from states and counties. The package comes with static data that was downloaded at the time of the last package update.

library(covid19nytimes)

head(covid19nytimes_states_demo) %>% knitr::kable()
datelocationlocation_typelocation_codelocation_code_typedata_typevalue
2020-04-12Alabamastate01fips_codecases_total3583
2020-04-12Alabamastate01fips_codedeaths_total93
2020-04-12Alaskastate02fips_codecases_total270
2020-04-12Alaskastate02fips_codedeaths_total6
2020-04-12American Samoastate60fips_codecases_total0
2020-04-12American Samoastate60fips_codedeaths_total0

head(covid19nytimes_counties_demo) %>% knitr::kable()
datelocationlocation_typelocation_codelocation_code_typedata_typevalue
2020-04-12Abbeville,South Carolinacounty_state45001fips_codecases_total9
2020-04-12Abbeville,South Carolinacounty_state45001fips_codedeaths_total0
2020-04-12Acadia,Louisianacounty_state22001fips_codecases_total99
2020-04-12Acadia,Louisianacounty_state22001fips_codedeaths_total5
2020-04-12Accomack,Virginiacounty_state51001fips_codecases_total15
2020-04-12Accomack,Virginiacounty_state51001fips_codedeaths_total0

Getting the Most Up to Date Data

To get the most updated data, run the following functions

covid19nytimes_states <- refresh_covid19nytimes_states()

covid19nytimes_counties <- refresh_covid19nytimes_counties()

Columns

The data follows the covid19R standard for tidy Covid-19 data. The data columns are as follows:

  • date - The date in YYYY-MM-DD form
  • location - The name of the location as provided by the data source. The counties dataset provides county and state. They are combined and separated by a ,, and can be split by tidyr::separate(), if you wish.
  • location_type - The type of location using the covid19R controlled vocabulary. Nested locations are indicated by multiple location types being combined with a `_
  • location_code - A standardized location code using a national or international standard. In this case, FIPS state or county codes. See https://en.wikipedia.org/wiki/Federal_Information_Processing_Standard_state_code and https://en.wikipedia.org/wiki/FIPS_county_code for more
  • location_code_type The type of standardized location code being used according to the covid19R controlled vocabulary. Here we use fips_code
  • data_type - the type of data in that given row. Includes total_cases and total_deaths, cumulative measures of both.
  • value - number of cases of each data type

Sample visualization

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(ggplot2)

covid19nytimes_states %>%
  filter(location %in% c("Washington", "New York", "Massachusetts", "Michigan", "Illinois")) %>%
  filter(data_type == "deaths_total") %>%
  ggplot(aes(x = date, y = value, color = location)) +
  geom_line() +
  theme_minimal(base_size=14) +
  scale_y_continuous()

Copy Link

Version

Install

install.packages('covid19nytimes')

Monthly Downloads

4

Version

0.1.3

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Jarrett Byrnes

Last Published

May 8th, 2020

Functions in covid19nytimes (0.1.3)

refresh_covid19nytimes_states

US State Data from the NY Times
get_info_covid19nytimes

Get information about the datasets provided by covid19nytimes
refresh_covid19nytimes_counties

US County Data from the NY Times
%>%

Pipe operator
covid19nytimes_states_demo

Demo of US State Data from the NY Times
covid19nytimes_counties_demo

Demo of US County-Level Data from the NY Times