-
Notifications
You must be signed in to change notification settings - Fork 210
/
README.Rmd
517 lines (417 loc) · 20.1 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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%",
message=FALSE,
warning=FALSE
)
library(coronavirus)
```
# coronavirus <a href='https://RamiKrispin.github.io/coronavirus/'><img src='man/figures/coronavirus.png' align="right" /></a>
<!-- badges: start --->
[![R-CMD](https://github.com/RamiKrispin/coronavirus/workflows/build/badge.svg?branch=master)](https://github.com/RamiKrispin/coronavirus/actions/workflows/main.yml)
[![Data Pipeline](https://github.com/RamiKrispin/coronavirus/actions/workflows/data_refresh.yml/badge.svg?branch=main)](https://github.com/RamiKrispin/coronavirus/actions/workflows/data_refresh.yml)
[![CRAN\_Status\_Badge](https://www.r-pkg.org/badges/version/coronavirus)](https://cran.r-project.org/package=coronavirus)
[![lifecycle](https://img.shields.io/badge/lifecycle-stable-green.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/license/mit/)
[![GitHub commit](https://img.shields.io/github/last-commit/RamiKrispin/coronavirus)](https://github.com/RamiKrispin/coronavirus/commit/master)
[![Downloads](https://cranlogs.r-pkg.org/badges/grand-total/coronavirus)](https://cran.r-project.org/package=coronavirus)
<!-- badges: end -->
The coronavirus package provides a tidy format for the COVID-19 dataset collected by the Center for Systems Science and Engineering (CSSE) at Johns Hopkins University. The dataset includes daily new and death cases between January 2020 and March 2023 and recovery cases until August 2022.
More details available [here](https://RamiKrispin.github.io/coronavirus/), and a `csv` format of the package dataset available [here](https://github.com/RamiKrispin/coronavirus/tree/master/csv)
Data source: https://github.com/CSSEGISandData/COVID-19
<img src="man/figures/2019-nCoV-CDC-23312_without_background.png" width="65%" align="center"/></a>
<figcaption>Source: Centers for Disease Control and Prevention's Public Health Image Library </figcaption>
## Important Notes
* As of March 10th, 2023, JHU CCSE stopped collecting and tracking new cases
* As of August 4th, 2022 JHU CCSE stopped track recovery cases, please see this [issue](https://github.com/RamiKrispin/coronavirus/issues/71) for more details
* Negative values and/or anomalies may occurred in the data for the following reasons:
* The calculation of the daily cases from the raw data which is in cumulative format is done by taking the daily difference. In some cases, some retro updates not tie to the day that they actually occurred such as removing false positive cases
* Anomalies or error in the raw data
* Please see this [issue](https://github.com/RamiKrispin/coronavirus/issues/55) for more details
## Vignettes
Additional documentation available on the following vignettes:
* [Introduction to the Coronavirus Dataset](https://ramikrispin.github.io/coronavirus/articles/intro_coronavirus_dataset.html)
* [Covid19R Project Data Format](https://ramikrispin.github.io/coronavirus/articles/covid19R.html)
* [Covid19 Vaccine Data](https://ramikrispin.github.io/coronavirus/articles/covid19_vaccine.html)
* [Geospatial Visualization](https://ramikrispin.github.io/coronavirus/articles/geospatial_visualization.html)
## Installation
Install the CRAN version:
```r
install.packages("coronavirus")
```
Install the Github version (refreshed on a daily bases):
``` r
# install.packages("devtools")
devtools::install_github("RamiKrispin/coronavirus")
```
## Datasets
The package provides the following two datasets:
* **coronavirus** - tidy (long) format of the JHU CCSE [datasets](https://github.com/CSSEGISandData/COVID-19/tree/master/csse_covid_19_data/csse_covid_19_time_series). That includes the following columns:
* `date` - The date of the observation, using `Date` class
* `province` - Name of province/state, for countries where data is provided split across multiple provinces/states
* `country` - Name of country/region
* `lat` - The latitude code
* `long` - The longitude code
* `type` - An indicator for the type of cases (confirmed, death, recovered)
* `cases` - Number of cases on given date
* `uid` - Country code
* `province_state` - Province or state if applicable
* `iso2` - Officially assigned country code identifiers with two-letter
* `iso3` - Officially assigned country code identifiers with three-letter
* `code3` - UN country code
* `fips` - Federal Information Processing Standards code that uniquely identifies counties within the USA
* `combined_key` - Country and province (if applicable)
* `population` - Country or province population
* `continent_name` - Continent name
* `continent_code` - Continent code
* **covid19_vaccine** - a tidy (long) format of the the Johns Hopkins [Centers for Civic Impact](https://govex.jhu.edu/) global vaccination [dataset](https://github.com/govex/COVID-19/tree/master/data_tables/vaccine_data) by country. This dataset includes the following columns:
* `country_region` - Country or region name
* `date` - Data collection date in YYYY-MM-DD format
* `doses_admin` - Cumulative number of doses administered. When a vaccine requires multiple doses, each one is counted independently
* `people_partially_vaccinated` - Cumulative number of people who received at least one vaccine dose. When the person receives a prescribed second dose, it is not counted twice
* `people_fully_vaccinated` - Cumulative number of people who received all prescribed doses necessary to be considered fully vaccinated
* `report_date_string` - Data report date in YYYY-MM-DD format
* `uid` - Country code
* `province_state` - Province or state if applicable
* `iso2` - Officially assigned country code identifiers with two-letter
* `iso3` - Officially assigned country code identifiers with three-letter
* `code3` - UN country code
* `fips` - Federal Information Processing Standards code that uniquely identifies counties within the USA
* `lat` - Latitude
* `long` - Longitude
* `combined_key` - Country and province (if applicable)
* `population` - Country or province population
* `continent_name` - Continent name
* `continent_code` - Continent code
The `refresh_coronavirus_jhu` function enables to load of the data directly from the package repository using the [Covid19R](https://covid19r.github.io/documentation/) project [data standard format](https://covid19r.github.io/documentation/data-format-standard.html):
```{r}
covid19_df <- refresh_coronavirus_jhu()
head(covid19_df)
```
## Usage
```{r}
data("coronavirus")
head(coronavirus)
```
Summary of the total confrimed cases by country (top 20):
```{r}
library(dplyr)
summary_df <- coronavirus %>%
filter(type == "confirmed") %>%
group_by(country) %>%
summarise(total_cases = sum(cases)) %>%
arrange(-total_cases)
summary_df %>% head(20)
```
Summary of new cases during the past 24 hours by country and type (as of `r max(coronavirus$date)`):
```{r}
library(tidyr)
coronavirus %>%
filter(date == max(date)) %>%
select(country, type, cases) %>%
group_by(country, type) %>%
summarise(total_cases = sum(cases)) %>%
pivot_wider(names_from = type,
values_from = total_cases) %>%
arrange(-confirmed)
```
Plotting daily confirmed and death cases in Brazil:
``` r
library(plotly)
coronavirus %>%
group_by(type, date) %>%
summarise(total_cases = sum(cases)) %>%
pivot_wider(names_from = type, values_from = total_cases) %>%
arrange(date) %>%
mutate(active = confirmed - death - recovery) %>%
mutate(active_total = cumsum(active),
recovered_total = cumsum(recovery),
death_total = cumsum(death)) %>%
plot_ly(x = ~ date,
y = ~ active_total,
name = 'Active',
fillcolor = '#1f77b4',
type = 'scatter',
mode = 'none',
stackgroup = 'one') %>%
add_trace(y = ~ death_total,
name = "Death",
fillcolor = '#E41317') %>%
add_trace(y = ~recovered_total,
name = 'Recovered',
fillcolor = 'forestgreen') %>%
layout(title = "Distribution of Covid19 Cases Worldwide",
legend = list(x = 0.1, y = 0.9),
yaxis = list(title = "Number of Cases"),
xaxis = list(title = "Source: Johns Hopkins University Center for Systems Science and Engineering"))
```
```{r include=FALSE}
library(plotly)
df <- coronavirus %>%
filter(country == "Brazil",
is.na(province))
p_1 <- plot_ly(data = df %>% filter(type == "confirmed"),
x = ~ date,
y = ~ cases,
name = "Confirmed",
type = "scatter",
mode = "line") %>%
layout(yaxis = list(title = "Cases"),
xaxis = list(title = ""))
p_2 <- plot_ly(data = df %>% filter(type == "death"),
x = ~ date,
y = ~ cases,
name = "Death",
line = list(color = "red"),
type = "scatter",
mode = "line") %>%
layout(yaxis = list(title = "Cases"),
xaxis = list(title = "Source: Johns Hopkins University Center for Systems Science and Engineering"))
p1 <- subplot(p_1, p_2, nrows = 2,
titleX = TRUE,
titleY = TRUE) %>%
layout(title = "Brazil - Daily Confirmed and Death Cases",
margin = list(t = 60, b = 60, l = 40, r = 40),
legend = list(x = 0.05, y = 1))
orca(p1, "man/figures/brazil_cases.svg")
```
<img src="man/figures/brazil_cases.svg" width="100%" />
Plot the confirmed cases distribution by counrty with treemap plot:
``` r
conf_df <- coronavirus %>%
filter(type == "confirmed") %>%
group_by(country) %>%
summarise(total_cases = sum(cases)) %>%
arrange(-total_cases) %>%
mutate(parents = "Confirmed") %>%
ungroup()
plot_ly(data = conf_df,
type= "treemap",
values = ~total_cases,
labels= ~ country,
parents= ~parents,
domain = list(column=0),
name = "Confirmed",
textinfo="label+value+percent parent")
```
```{r include=FALSE}
conf_df <- coronavirus %>%
filter(type == "confirmed") %>%
group_by(country) %>%
summarise(total_cases = sum(cases), .groups = "drop") %>%
arrange(-total_cases) %>%
mutate(parents = "Confirmed") %>%
ungroup()
p2 <- plot_ly(data = conf_df,
type= "treemap",
values = ~total_cases,
labels= ~ country,
parents= ~parents,
domain = list(column=0),
name = "Confirmed",
textinfo="label+value+percent parent")
orca(p2, "man/figures/treemap_conf.svg")
```
<img src="man/figures/treemap_conf.svg" width="100%" />
```{r}
data(covid19_vaccine)
head(covid19_vaccine)
```
Taking a snapshot of the data from the most recent date available and calculate the ratio between total doses admin and the population size:
```{r}
df_summary <- covid19_vaccine |>
filter(date == max(date)) |>
select(date, country_region, doses_admin, total = people_at_least_one_dose, population, continent_name) |>
mutate(doses_pop_ratio = doses_admin / population,
total_pop_ratio = total / population) |>
filter(country_region != "World",
!is.na(population),
!is.na(total)) |>
arrange(- total)
head(df_summary, 10)
```
Plot of the total doses and population ratio by country:
```r
# Setting the diagonal lines range
line_start <- 10000
line_end <- 1500 * 10 ^ 6
# Filter the data
d <- df_summary |>
filter(country_region != "World",
!is.na(population),
!is.na(total))
# Replot it
p3 <- plot_ly() |>
add_markers(x = d$population,
y = d$total,
text = ~ paste("Country: ", d$country_region, "<br>",
"Population: ", d$population, "<br>",
"Total Doses: ", d$total, "<br>",
"Ratio: ", round(d$total_pop_ratio, 2),
sep = ""),
color = d$continent_name,
type = "scatter",
mode = "markers") |>
add_lines(x = c(line_start, line_end),
y = c(line_start, line_end),
showlegend = FALSE,
line = list(color = "gray", width = 0.5)) |>
add_lines(x = c(line_start, line_end),
y = c(0.5 * line_start, 0.5 * line_end),
showlegend = FALSE,
line = list(color = "gray", width = 0.5)) |>
add_lines(x = c(line_start, line_end),
y = c(0.25 * line_start, 0.25 * line_end),
showlegend = FALSE,
line = list(color = "gray", width = 0.5)) |>
add_annotations(text = "1:1",
x = log10(line_end * 1.25),
y = log10(line_end * 1.25),
showarrow = FALSE,
textangle = -25,
font = list(size = 8),
xref = "x",
yref = "y") |>
add_annotations(text = "1:2",
x = log10(line_end * 1.25),
y = log10(0.5 * line_end * 1.25),
showarrow = FALSE,
textangle = -25,
font = list(size = 8),
xref = "x",
yref = "y") |>
add_annotations(text = "1:4",
x = log10(line_end * 1.25),
y = log10(0.25 * line_end * 1.25),
showarrow = FALSE,
textangle = -25,
font = list(size = 8),
xref = "x",
yref = "y") |>
add_annotations(text = "Source: Johns Hopkins University - Centers for Civic Impact",
showarrow = FALSE,
xref = "paper",
yref = "paper",
x = -0.05, y = - 0.33) |>
layout(title = "Covid19 Vaccine - Total Doses vs. Population Ratio (Log Scale)",
margin = list(l = 50, r = 50, b = 90, t = 70),
yaxis = list(title = "Number of Doses",
type = "log"),
xaxis = list(title = "Population Size",
type = "log"),
legend = list(x = 0.75, y = 0.05))
```
```{r include=FALSE}
# Setting the diagonal lines range
line_start <- 10000
line_end <- 1500 * 10 ^ 6
# Filter the data
d <- df_summary |>
filter(country_region != "World",
!is.na(population),
!is.na(total))
# Replot it
p3 <- plot_ly() |>
add_markers(x = d$population,
y = d$total,
text = ~ paste("Country: ", d$country_region, "<br>",
"Population: ", d$population, "<br>",
"Total Doses: ", d$total, "<br>",
"Ratio: ", round(d$total_pop_ratio, 2),
sep = ""),
color = d$continent_name,
type = "scatter",
mode = "markers") |>
add_lines(x = c(line_start, line_end),
y = c(line_start, line_end),
showlegend = FALSE,
line = list(color = "gray", width = 0.5)) |>
add_lines(x = c(line_start, line_end),
y = c(0.5 * line_start, 0.5 * line_end),
showlegend = FALSE,
line = list(color = "gray", width = 0.5)) |>
add_lines(x = c(line_start, line_end),
y = c(0.25 * line_start, 0.25 * line_end),
showlegend = FALSE,
line = list(color = "gray", width = 0.5)) |>
add_annotations(text = "1:1",
x = log10(line_end * 1.25),
y = log10(line_end * 1.25),
showarrow = FALSE,
textangle = -25,
font = list(size = 8),
xref = "x",
yref = "y") |>
add_annotations(text = "1:2",
x = log10(line_end * 1.25),
y = log10(0.5 * line_end * 1.25),
showarrow = FALSE,
textangle = -25,
font = list(size = 8),
xref = "x",
yref = "y") |>
add_annotations(text = "1:4",
x = log10(line_end * 1.25),
y = log10(0.25 * line_end * 1.25),
showarrow = FALSE,
textangle = -25,
font = list(size = 8),
xref = "x",
yref = "y") |>
add_annotations(text = "Source: Johns Hopkins University - Centers for Civic Impact",
showarrow = FALSE,
xref = "paper",
yref = "paper",
x = -0.05, y = - 0.33) |>
layout(title = "Covid19 Vaccine - Total Doses vs. Population Ratio (Log Scale)",
margin = list(l = 50, r = 50, b = 90, t = 70),
yaxis = list(title = "Number of Doses",
type = "log"),
xaxis = list(title = "Population Size",
type = "log"),
legend = list(x = 0.75, y = 0.05))
orca(p3, "man/figures/country_summary.svg")
```
<img src="man/figures/country_summary.svg" width="100%" />
## Dashboard
**Note:** Currently, the dashboard is under maintenance due to recent changes in the data structure. Please see this [issue](https://github.com/RamiKrispin/coronavirus_dashboard/issues/25)
A supporting dashboard is available [here](https://ramikrispin.github.io/coronavirus_dashboard/)
[<img src="man/figures/dashboard.png" width="100%" />](https://ramikrispin.github.io/coronavirus_dashboard/)
## Data Sources
The raw data pulled and arranged by the Johns Hopkins University Center for Systems Science and Engineering (JHU CCSE) from the following resources:
* World Health Organization (WHO): https://www.who.int/ <br>
* DXY.cn. Pneumonia. 2020. https://ncov.dxy.cn/ncovh5/view/pneumonia. <br>
* BNO News: https://bnonews.com/index.php/2020/04/the-latest-coronavirus-cases/ <br>
* National Health Commission of the People’s Republic of China (NHC): <br>
http:://www.nhc.gov.cn/xcs/yqtb/list_gzbd.shtml <br>
* China CDC (CCDC): http:://weekly.chinacdc.cn/news/TrackingtheEpidemic.htm <br>
* Hong Kong Department of Health: https://www.chp.gov.hk/en/features/102465.html <br>
* Macau Government: https://www.ssm.gov.mo/portal/ <br>
* Taiwan CDC: https://sites.google.com/cdc.gov.tw/2019ncov/taiwan?authuser=0 <br>
* US CDC: https://www.cdc.gov/coronavirus/2019-ncov/index.html <br>
* Government of Canada: https://www.canada.ca/en/public-health/services/diseases/2019-novel-coronavirus-infection/symptoms.html <br>
* Australia Government Department of Health:https://www.health.gov.au/health-alerts/covid-19 <br>
* European Centre for Disease Prevention and Control (ECDC): https://www.ecdc.europa.eu/en/covid-19/country-overviews
* Ministry of Health Singapore (MOH): https://www.moh.gov.sg/covid-19
* Italy Ministry of Health: https://www.salute.gov.it/nuovocoronavirus
* 1Point3Arces: https://coronavirus.1point3acres.com/en
* WorldoMeters: https://www.worldometers.info/coronavirus/
* COVID Tracking Project: https://covidtracking.com/data/. (US Testing and Hospitalization Data. We use the maximum reported value from "Currently" and "Cumulative" Hospitalized for our hospitalization number reported for each state.)
* French Government: https://dashboard.covid19.data.gouv.fr/
* COVID Live (Australia): https://covidlive.com.au/
* Washington State Department of Health:https://doh.wa.gov/emergencies/covid-19
* Maryland Department of Health: https://coronavirus.maryland.gov/
* New York State Department of Health: https://health.data.ny.gov/Health/New-York-State-Statewide-COVID-19-Testing/xdss-u53e/data
* NYC Department of Health and Mental Hygiene: https://www.nyc.gov/site/doh/covid/covid-19-data.page and https://github.com/nychealth/coronavirus-data
* Florida Department of Health Dashboard: https://services1.arcgis.com/CY1LXxl9zlJeBuRZ/arcgis/rest/services/Florida_COVID19_Cases/FeatureServer/0
and https://fdoh.maps.arcgis.com/apps/dashboards/index.html#/8d0de33f260d444c852a615dc7837c86
* Palestine (West Bank and Gaza): https://corona.ps/details
* Israel: https://govextra.gov.il/ministry-of-health/corona/corona-virus/
* Colorado: https://covid19.colorado.gov/