[API] covidvirus: Application

Daily summary of the Covid-19 cases per state/region

Thierry Warin https://warin.ca/aboutme.html (HEC Montréal and CIRANO (Canada))https://www.hec.ca/en/profs/thierry.warin.html
03-02-2020

This course will teach you how to use the covidvirus package.

The covidvirus package provides a tidy format dataset of the 2019 Novel Coronavirus COVID-19 (2019-nCoV) epidemic. The raw data pulled from the Johns Hopkins University Center for Systems Science and Engineering (JHU CCSE) Coronavirus repository.

The covidvirus package was inspired by Rami Krispin’s coronavirus package. The key difference is that Rami’s package provides a dataset which must be manually updated from the package author’s perspective. In this package, Nik Agarwal used (i.e, respectfully copied) Rami Krispin’s data retrieval code and modified it to use substantially more “tidyverse” packages such as janitor, lubridate, etc. Another key difference is the name of columns. Since Nik used the package janitor, the column names use a ‘snake’ style and do not have dots ‘.’ (opting for the underscore ’_’).

How to use the covidvirus package

Installation

You can install the development version from GitHub with :


install.packages("devtools")
devtools::install_github("nikdata/covidvirus")

Usage

This is a basic example which shows you how to solve a common problem :


library(covidvirus)
corona_virus <- get_cases(wide=FALSE)

library(dplyr)
library(leaflet)
library(leaflet.extras)

Data Wrangling


# rename the country region
corona_virus$country_region <- gsub("United States", "USA", corona_virus$country_region)
corona_virus$country_region <- gsub("Mainland China", "China", corona_virus$country_region) 

# if the province state in the column is NA, paste the country region name in the column
corona_virus$name <- ifelse(is.na(corona_virus$province_state) == TRUE, 
                                paste0(corona_virus$country_region), paste0(corona_virus$province_state))

#filter the data
corona_virus <- filter(corona_virus, type == "confirmed")
corona_virus <- filter(corona_virus, date == "2020-04-07")

# ifelse ladder statement
corona_virus$category <- ifelse(corona_virus$cases >= -1 & corona_virus$cases <= 0, 0,
                                   ifelse(corona_virus$cases >= 1 & corona_virus$cases <= 10, 1,
                                   ifelse(corona_virus$cases >= 11 & corona_virus$cases <= 100, 2,
                                   ifelse(corona_virus$cases >= 101 & corona_virus$cases <= 1000, 5,
                                   ifelse(corona_virus$cases >= 1001 & corona_virus$cases <= 5000, 8,
                                   ifelse(corona_virus$cases >= 5001 & corona_virus$cases <= 10000, 10,
                                   ifelse(corona_virus$cases >= 10001 & corona_virus$cases <= 50000, 12,
                                   ifelse(corona_virus$cases >= 50001 & corona_virus$cases <= 100000, 15,
                                   ifelse(corona_virus$cases >= 100001 & corona_virus$cases <= Inf, 20,25)))))))))

Visualize your Data


content <- paste("<strong>", corona_virus$name, "</strong>", "<br/>", corona_virus$cases, "Cases")

leaflet(corona_virus) %>% 
  addFullscreenControl() %>%
  addProviderTiles(providers$CartoDB.DarkMatter) %>%
  addCircleMarkers(
    radius = ~sqrt(category)*5, popup = content,
    color = "red",
    stroke = FALSE, fillOpacity = 0.3
  )

Citation

For attribution, please cite this work as

Warin (2020, March 2). Thierry Warin: [API] covidvirus: Application. Retrieved from https://warin.ca/posts/api-covidvirus-application/

BibTeX citation

@misc{warin2020[api],
  author = {Warin, Thierry},
  title = {Thierry Warin: [API] covidvirus: Application},
  url = {https://warin.ca/posts/api-covidvirus-application/},
  year = {2020}
}