-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.Rmd
313 lines (258 loc) · 11.7 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
---
output: github_document
editor_options:
chunk_output_type: console
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
warning = FALSE,
message = FALSE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# covid19viz
<!-- badges: start -->
[![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)
<!-- badges: end -->
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 released version of covid19viz from [CRAN](https://CRAN.R-project.org) with:
``` r
install.packages("covid19viz")
```
-->
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 <chr> "AE", "AE", "AE", ...
#> $ country_region <chr> "United Arab Emira...
#> $ sub_region_1 <chr> NA, NA, NA, NA, NA...
#> $ sub_region_2 <lgl> NA, NA, NA, NA, NA...
#> $ metro_area <lgl> NA, NA, NA, NA, NA...
#> $ iso_3166_2_code <chr> NA, NA, NA, NA, NA...
#> $ census_fips_code <lgl> NA, NA, NA, NA, NA...
#> $ date <date> 2020-02-15, 2020-...
#> $ retail_and_recreation_percent_change_from_baseline <dbl> 0, 1, -1, -2, -2, ...
#> $ grocery_and_pharmacy_percent_change_from_baseline <dbl> 4, 4, 1, 1, 0, 1, ...
#> $ parks_percent_change_from_baseline <dbl> 5, 4, 5, 5, 4, 6, ...
#> $ transit_stations_percent_change_from_baseline <dbl> 0, 1, 1, 0, -1, 1,...
#> $ workplaces_percent_change_from_baseline <dbl> 2, 2, 2, 2, 2, 1, ...
#> $ residential_percent_change_from_baseline <dbl> 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
#> <chr> <chr> <dbl> <dttm>
#> 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 <chr> "PE", "PE", "PE", ...
#> $ country_region <chr> "Peru", "Peru", "P...
#> $ sub_region_1 <chr> NA, NA, NA, NA, NA...
#> $ sub_region_2 <chr> NA, NA, NA, NA, NA...
#> $ metro_area <lgl> NA, NA, NA, NA, NA...
#> $ iso_3166_2_code <chr> NA, NA, NA, NA, NA...
#> $ census_fips_code <lgl> NA, NA, NA, NA, NA...
#> $ date <date> 2020-02-15, 2020-...
#> $ retail_and_recreation_percent_change_from_baseline <dbl> 4, 1, 0, 0, 0, 0, ...
#> $ grocery_and_pharmacy_percent_change_from_baseline <dbl> 1, 0, 1, 0, -1, -1...
#> $ parks_percent_change_from_baseline <dbl> 3, -2, 1, 0, 0, -1...
#> $ transit_stations_percent_change_from_baseline <dbl> 3, 2, 2, 1, 0, 3, ...
#> $ workplaces_percent_change_from_baseline <dbl> 0, 0, 1, 1, 1, 0, ...
#> $ residential_percent_change_from_baseline <dbl> -1, 0, 0, 0, 1, 0,...
peru %>% count(sub_region_1)
#> # A tibble: 27 x 2
#> sub_region_1 n
#> <chr> <int>
#> 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 <chr> "Afghanistan", "Albania", "Algeria", "Angola",...
#> $ ISO3 <chr> "AFG", "ALB", "DZA", "AGO", "ATG", "ARG", "ARM...
#> $ REGION <chr> "Asia", "Europe", "Africa", "Africa", "America...
#> $ Measure_taxonomy <chr> "Schools closure ", "Border checks ", "Border ...
#> $ Measure_Category <chr> "Social distancing", "Movement restrictions", ...
#> $ SOURCE_TYPE <chr> "Government", "Media", "UN", "Other organisati...
#> $ Enforcement_taxonomy <chr> "Fines", "Arrest/Detention", "Deportation", "R...
#> $ Log_type <chr> "Introduction / extension of measures", "Phase...
# unesco education data
read_unesco_education() %>% glimpse()
#> Rows: 41,714
#> Columns: 5
#> $ Date <chr> "17/02/2020", "17/02/2020", "18/02/2020", "...
#> $ ISO <chr> "CHN", "MNG", "CHN", "MNG", "CHN", "MNG", "...
#> $ Country <chr> "China", "Mongolia", "China", "Mongolia", "...
#> $ Status <chr> "Partially open", "Closed due to COVID-19",...
#> $ Note <lgl> 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<max_analysis_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")
```