knitr::opts_chunk$set( collapse = TRUE, message=FALSE, warning=FALSE, comment = "#>" )
The covid19swiss R package provides a tidy format dataset of the 2019 Novel Coronavirus COVID-19 (2019-nCoV) pandemic outbreak in Switzerland cantons and Principality of Liechtenstein (FL).
The covid19swiss
dataset includes the following fields:
date
- the timestamp of the case, a Date
objectlocation
- the cantons of Switzerland and Principality of Liechtenstein (FL) abbreviation codelocation_type
- description of the location, either Canton of Switzerland or the Principality of echtensteinlocation_code
- a canton index code for merging geometry data from the rnaturalearth package, ailable only for Switzerland cantonslocation_code_type
- the name of code in the rnaturalearth package for Switzerland mapdata_type
- the type of casevalue
- the number of cases corresponding to the date
and data_type
fieldsWhere the available data_type
field includes the following cases:
total_tested
- number of tests performed as of the datetotal_confirmed
- number of positive cases as of the datenew_hosp
- new hospitalizations with respect to the previously reported datecurrent_hosp
- number of hospitalized patients as of the current datecurrent_icu
- number of hospitalized patients in ICUs as of the current datecurrent_vent
- number of hospitalized patients requiring ventilation as of the current datetotal_recovered
- total number of patients recovered as of the current datetotal_death
- total number of death as of the current dateThe data organized in a long format:
library(covid19swiss) head(covid19swiss)
It is straightforward to transform the data into a wide format with the pivot_wider
function from the tidyr package:
library(tidyr) covid19swiss_wide <- covid19swiss %>% pivot_wider(names_from = data_type, values_from = value) head(covid19swiss_wide)
The following examples demonstrate simple methods for query and summarise the data with the dplyr and tidyr packages.
The first example demonstrates how to query the total confirmed, recovered, and death cases by canton as of April 8th:
library(dplyr) covid19swiss %>% filter(date == as.Date("2020-04-10"), data_type %in% c("total_confirmed", "total_recovered", "total_death")) %>% select(location, value, data_type) %>% pivot_wider(names_from = data_type, values_from = value) %>% arrange(-total_confirmed)
Note: some fields, such as total_recovered
or total_tested
, are not available for some cantons and marked as missing values (i.e., NA
)
In the next example, we will filter the dataset for the Canton of Geneva and calculate the following metrics:
covid19swiss %>% dplyr::filter(location == "GE", date == as.Date("2020-04-10")) %>% dplyr::select(data_type, value) %>% tidyr::pivot_wider(names_from = data_type, values_from = value) %>% dplyr::mutate(positive_tested = round(100 * total_confirmed / total_tested, 2), death_rate = round(100 * total_death / total_confirmed, 2), recovery_rate = round(100 * total_recovered / total_confirmed, 2)) %>% dplyr::select(positive_tested, recovery_rate, death_rate)
Values are in precentage
The raw data include both Switzerland and the Principality of Liechtenstein. Separating the data by country can be done by using the location
field:
switzerland <- covid19swiss %>% filter(location != "FL") head(switzerland) liechtenstein <- covid19swiss %>% filter(location == "FL") head(liechtenstein)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.