Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/avallecam/covid19viz

Visualize COVID-19 country-level data of cases, mobility and interventions
https://github.com/avallecam/covid19viz

acaps coronavirus covid-19 covid19 education rstats unesco

Last synced: 29 days ago
JSON representation

Visualize COVID-19 country-level data of cases, mobility and interventions

Awesome Lists containing this project

README

        

---
output: github_document
editor_options:
chunk_output_type: console
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
warning = FALSE,
message = FALSE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# covid19viz

[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
[![CRAN status](https://www.r-pkg.org/badges/version/covid19viz)](https://cran.r-project.org/package=covid19viz)
[![DOI](https://zenodo.org/badge/246721190.svg)](https://zenodo.org/badge/latestdoi/246721190)

The goal of `covid19viz` is to access and summarize WHO sitreps for covid-19 in simple graphics.

This package works using two data repositories:

- digitalized __WHO sitreps__ by [Fabienne Krauer](https://twitter.com/FabiKrauer) available in [fkrauer/COVID-19](https://github.com/fkrauer/COVID-19).

- Johns Hopkins University __(JHU CSSE)__ available in [CSSEGISandData/COVID-19](https://github.com/CSSEGISandData/COVID-19).

Additionally, it imports external data sources like:

- __Google__ Mobility Reports. [View](https://www.google.com/covid19/mobility/).

- __ACAPS__ data on #COVID19 Government Measures Dataset. [View](https://www.acaps.org/covid19-government-measures-dataset).

- __UNESCO__ COVID-19 Impact on Education. [View](https://en.unesco.org/covid19/educationresponse).

## Installation

You can install the development version of `covid19viz` using:

``` r
if(!require("remotes")) install.packages("remotes")
remotes::install_github("avallecam/covid19viz")
```

## Quick Examples

### Import and visualize JHU collection

```{r}
library(covid19viz)
library(tidyverse)

#import all data at once
jhu_sitrep_peru <- jhu_sitrep_all_sources(country_region="Peru")

jhu_sitrep_peru

#transform to tidy format
jhu_sitrep_peru %>%
jhu_sitrep_all_sources_tidy() %>%
arrange(desc(confirmed_cumulative)) %>%
glimpse()
```

```{r,fig.width=8,fig.height=4,fig.align='center'}
jhu_sitrep_country_report(country_region = "Peru")
```

### Import more external data sources

- Google Mobility Reports. [View](https://www.google.com/covid19/mobility/).
- ACAPS data on #COVID19 Government Measures Dataset. [View](https://www.acaps.org/covid19-government-measures-dataset).
- UNESCO COVID-19 Impact on Education. [View](https://en.unesco.org/covid19/educationresponse).

```{r,eval=FALSE}
library(covid19viz)
library(tidyverse)

# google mobility reports
# global
read_google_global() %>% glimpse()
#> Rows: 2,441,517
#> Columns: 14
#> $ country_region_code "AE", "AE", "AE", ...
#> $ country_region "United Arab Emira...
#> $ sub_region_1 NA, NA, NA, NA, NA...
#> $ sub_region_2 NA, NA, NA, NA, NA...
#> $ metro_area NA, NA, NA, NA, NA...
#> $ iso_3166_2_code NA, NA, NA, NA, NA...
#> $ census_fips_code NA, NA, NA, NA, NA...
#> $ date 2020-02-15, 2020-...
#> $ retail_and_recreation_percent_change_from_baseline 0, 1, -1, -2, -2, ...
#> $ grocery_and_pharmacy_percent_change_from_baseline 4, 4, 1, 1, 0, 1, ...
#> $ parks_percent_change_from_baseline 5, 4, 5, 5, 4, 6, ...
#> $ transit_stations_percent_change_from_baseline 0, 1, 1, 0, -1, 1,...
#> $ workplaces_percent_change_from_baseline 2, 2, 2, 2, 2, 1, ...
#> $ residential_percent_change_from_baseline 1, 1, 1, 1, 1, 1, ...

# regional
# first: select country ISO
read_google_region_list()
#> # A tibble: 135 x 4
#> country_iso Name Length Date
#>
#> 1 AE 2020_AE_Region_Mobility_Report.csv 121354 2020-09-13 15:27:00
#> 2 AF 2020_AF_Region_Mobility_Report.csv 20553 2020-09-13 15:27:00
#> 3 AG 2020_AG_Region_Mobility_Report.csv 57484 2020-09-13 15:27:00
#> 4 AO 2020_AO_Region_Mobility_Report.csv 58954 2020-09-13 15:27:00
#> 5 AR 2020_AR_Region_Mobility_Report.csv 6932241 2020-09-13 15:27:00
#> 6 AT 2020_AT_Region_Mobility_Report.csv 1402047 2020-09-13 15:27:00
#> 7 AU 2020_AU_Region_Mobility_Report.csv 4329094 2020-09-13 15:27:00
#> 8 AW 2020_AW_Region_Mobility_Report.csv 9967 2020-09-13 15:27:00

# second: read specific country data
peru <- read_google_region_country(country_iso = "PE")
peru %>% glimpse()
#> Rows: 28,194
#> Columns: 14
#> $ country_region_code "PE", "PE", "PE", ...
#> $ country_region "Peru", "Peru", "P...
#> $ sub_region_1 NA, NA, NA, NA, NA...
#> $ sub_region_2 NA, NA, NA, NA, NA...
#> $ metro_area NA, NA, NA, NA, NA...
#> $ iso_3166_2_code NA, NA, NA, NA, NA...
#> $ census_fips_code NA, NA, NA, NA, NA...
#> $ date 2020-02-15, 2020-...
#> $ retail_and_recreation_percent_change_from_baseline 4, 1, 0, 0, 0, 0, ...
#> $ grocery_and_pharmacy_percent_change_from_baseline 1, 0, 1, 0, -1, -1...
#> $ parks_percent_change_from_baseline 3, -2, 1, 0, 0, -1...
#> $ transit_stations_percent_change_from_baseline 3, 2, 2, 1, 0, 3, ...
#> $ workplaces_percent_change_from_baseline 0, 0, 1, 1, 1, 0, ...
#> $ residential_percent_change_from_baseline -1, 0, 0, 0, 1, 0,...

peru %>% count(sub_region_1)
#> # A tibble: 27 x 2
#> sub_region_1 n
#>
#> 1 Amazonas 1050
#> 2 Ancash 1871
#> 3 Apurimac 816
#> 4 Arequipa 1470
#> 5 Ayacucho 1050
#> 6 Cajamarca 1850
#> 7 Callao Region 210
#> 8 Cusco 1668
#> 9 Huancavelica 630
#> 10 Huanuco 630
#> # ... with 17 more rows

# acaps data
read_acaps_governments() %>% glimpse()
#> Rows: 193
#> Columns: 8
#> $ Country_name "Afghanistan", "Albania", "Algeria", "Angola",...
#> $ ISO3 "AFG", "ALB", "DZA", "AGO", "ATG", "ARG", "ARM...
#> $ REGION "Asia", "Europe", "Africa", "Africa", "America...
#> $ Measure_taxonomy "Schools closure ", "Border checks ", "Border ...
#> $ Measure_Category "Social distancing", "Movement restrictions", ...
#> $ SOURCE_TYPE "Government", "Media", "UN", "Other organisati...
#> $ Enforcement_taxonomy "Fines", "Arrest/Detention", "Deportation", "R...
#> $ Log_type "Introduction / extension of measures", "Phase...

# unesco education data
read_unesco_education() %>% glimpse()
#> Rows: 41,714
#> Columns: 5
#> $ Date "17/02/2020", "17/02/2020", "18/02/2020", "...
#> $ ISO "CHN", "MNG", "CHN", "MNG", "CHN", "MNG", "...
#> $ Country "China", "Mongolia", "China", "Mongolia", "...
#> $ Status "Partially open", "Closed due to COVID-19",...
#> $ Note NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,...
```

```{r,echo=FALSE,fig.height=4,fig.width=10,fig.retina=TRUE}
# library(covidPeru); library(readr)
library(covid19viz)
# library(cdcper)
library(tidyverse)
library(lubridate)
theme_set(theme_bw())

# analysis time limits --------------------------------------------------------------

min_analysis_date <- ymd(20200301)
max_analysis_date <- Sys.Date()

# covid19viz R package ----------------------------------------------------

# _import intervention data ------------------------------------------------

unesco <- read_unesco_education()
# acaps <- read_acaps_governments()

# no data in ACAPS
# acaps %>% filter(ISO3=="PER")

unesco_peru <- unesco %>%
filter(ISO=="PER") %>%
mutate(Date=dmy(Date)) %>%
group_by(Status) %>%
summarise(date_min=min(Date),
date_max=max(Date)) %>%
rename(intervention_label=Status) %>%
mutate(intervention=case_when(
intervention_label=="Closed due to COVID-19" ~ "closed",
intervention_label=="Partially open" ~ "partial"
))
# unesco_peru

# _unite intervention data -------------------------------------------------

interventions <- tibble(
date_min = ymd(20200628),
date_max = ymd(20200709),
intervention_label = "Seroprevalence study",
intervention = "seroprev"
) %>%
union_all(
unesco_peru %>%
mutate(date_max=if_else(date_max==max(date_max),
max_analysis_date,
date_max))
)
# interventions

# mobility data -----------------------------------------------------------

mobility <- read_google_region_country(country_iso = "PE")
# mobility %>% count(sub_region_1) %>% print(n=Inf)
# mobility %>% count(country_region,sub_region_1,sub_region_2,metro_area) %>% print(n=Inf)
mobility_lima <- mobility %>%
filter(date%
filter(
magrittr::is_in(sub_region_1,c("Metropolitan Municipality of Lima",
"Callao Region"))) %>%
mutate(across(c(sub_region_1,sub_region_2,metro_area),
str_replace_na,replacement = "")) %>%
mutate(subregion=str_c(sub_region_1,"\n",sub_region_2,"\n",metro_area)) %>%
mutate(subregion=str_trim(subregion)) %>%
mutate(subregion=if_else(sub_region_1=="Metropolitan Municipality of Lima",
"Metropolitan Municipality\nof Lima",subregion)) %>%
# count(country_region,subregion)
filter(!(sub_region_1=="Metropolitan Municipality of Lima" &
sub_region_2=="")) %>%
# count(country_region,sub_region_1,sub_region_2,metro_area,subregion)
# pivot_longer()
pivot_longer(cols = -c(country_region_code:date,subregion),
names_to = "field",
names_pattern = "(.+)_percent_change_from_baseline",
values_to = "percent_change_from_baseline")

# plot all --------------------------------------

mobility_lima %>%
mutate(field=str_replace_all(field,"_"," "),
field=str_to_sentence(field)) %>%
ggplot() +
geom_rect(data = interventions,
aes(xmin = date_min, xmax = date_max,
ymin = -Inf, ymax = Inf,
fill =intervention_label),
alpha=0.2) +
geom_hline(aes(yintercept=0),lty=2) +
geom_line(aes(x = date,percent_change_from_baseline, color=subregion)) +
geom_smooth(aes(x = date,percent_change_from_baseline, color=subregion),
span = 0.1) +
facet_wrap(~field) +
colorspace::scale_color_discrete_qualitative() +
scale_x_date(date_breaks = "1 month",date_labels = "%b") +
# theme(legend.position="bottom")
labs(title = "Government interventions and Google mobility reports",
subtitle = "Lima Metropolitan Area and Callao Region, Peru 2020",
x = "Date",
y = "% change from baseline",
fill = "Interventions",
color = "Region")
```

### Import initial stages of the WHO sitreps

- Created and maintained by [Fabienne Krauer](https://github.com/fkrauer/COVID-19)

```{r,fig.height=7.5,fig.width=9}
library(covid19viz)

# paste last update available at
# https://github.com/fkrauer/COVID-19
update <- "2020-03-10"

# apply
who_sitrep_country_report(
update = update,
country_region = "Brazil")
```