-
Notifications
You must be signed in to change notification settings - Fork 9
/
README.Rmd
203 lines (142 loc) · 8.11 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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
dpi=200,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
<img src="man/figures/COVID19analytics.png" height="139" align="right" />
# COVID19analytics
<!-- . -->
This package curate (downloads, clean, consolidate, smooth) data from [Johns Hopkins](https://github.com/CSSEGISandData/COVID-19/) and [Our world in data](https://ourworldindata.org/coronavirus) for analysing international outbreak of COVID-19.
It includes several visualizations of the COVID-19 international outbreak.
* COVID19DataProcessor generates curated series
* [visualizations](https://www.r-bloggers.com/coronavirus-data-analysis-with-r-tidyverse-and-ggplot2/) by [Yanchang Zhao](https://www.r-bloggers.com/author/yanchang-zhao/) are included in ReportGenerator R6 object
* More visualizations included int ReportGeneratorEnhanced R6 object
* Visualizations ReportGeneratorDataComparison compares all countries counting epidemy day 0 when confirmed cases > n (i.e. n = 100).
# Package
<!-- badges: start -->
| Release | Usage | Development |
|:--------|:------|:------------|
| | [![minimal R version](https://img.shields.io/badge/R%3E%3D-3.4.0-blue.svg)](https://cran.r-project.org/) | [![Travis](https://travis-ci.org/rOpenStats/COVID19analytics.svg?branch=master)](https://travis-ci.org/rOpenStats/COVID19analytics) |
| [![CRAN](http://www.r-pkg.org/badges/version/COVID19analytics)](https://cran.r-project.org/package=COVID19analytics) | | [![codecov](https://codecov.io/gh/rOpenStats/COVID19analytics/branch/master/graph/badge.svg)](https://codecov.io/gh/rOpenStats/COVID19analytics) |
|||[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)|
<!-- badges: end -->
# How to get started (Development version)
Install the R package using the following commands on the R console:
```R
# install.packages("devtools")
devtools::install_github("rOpenStats/COVID19analytics", build_opts = NULL)
```
First configurate environment variables with your preferred configurations in `~/.Renviron`. COVID19analytics_data_dir is mandatory while COVID19analytics_credits can be configured if you want to publish your own research with space separated alias. Mention previous authors where corresponding
```.Renviron
COVID19analytics_data_dir = "~/.R/COVID19analytics"
# If you want to generate your own reports
COVID19analytics_credits = "@alias1 @alias2 @aliasn"
```
# How to use it
```{r, libraries}
library(COVID19analytics)
library(dplyr)
library(knitr)
library(lgr)
```
```{r, log-config}
log.dir <- file.path(getEnv("data_dir"), "logs")
dir.create(log.dir, recursive = TRUE, showWarnings = FALSE)
log.file <- file.path(log.dir, "covid19analytics.log")
lgr::get_logger("root")$add_appender(AppenderFile$new(log.file))
lgr::threshold("info", lgr::get_logger("root"))
lgr::threshold("info", lgr::get_logger("COVID19ARCurator"))
```
```{r, load-processor}
data.processor <- COVID19DataProcessor$new(provider = "JohnsHopkingsUniversity", missing.values = "imputation")
#dummy <- data.processor$preprocess() is setupData + transform is the preprocess made by data provider
dummy <- data.processor$setupData()
dummy <- data.processor$transform()
# Curate is the process made by missing values method
dummy <- data.processor$curate()
current.date <- max(data.processor$getData()$date)
rg <- ReportGeneratorEnhanced$new(data.processor)
rc <- ReportGeneratorDataComparison$new(data.processor = data.processor)
top.countries <- data.processor$top.countries
international.countries <- unique(c(data.processor$top.countries,
"China", "Japan", "Singapore", "Korea, South"))
latam.countries <- sort(c("Mexico",
data.processor$countries$getCountries(division = "sub.continent", name = "Caribbean"),
data.processor$countries$getCountries(division = "sub.continent", name = "Central America"),
data.processor$countries$getCountries(division = "sub.continent", name = "South America")))
```
```{r, top-countries-confirmed-inc}
# Top 10 daily cases confirmed increment
kable((data.processor$getData() %>%
filter(date == current.date) %>%
select(country, date, rate.inc.daily, confirmed.inc, confirmed, deaths, deaths.inc) %>%
arrange(desc(confirmed.inc)) %>%
filter(confirmed >=10))[1:10,])
```
```{r, top-countries-confirmed-deaths}
# Top 10 daily deaths increment
kable((data.processor$getData() %>%
filter(date == current.date) %>%
select(country, date, rate.inc.daily, confirmed.inc, confirmed, deaths, deaths.inc) %>%
arrange(desc(deaths.inc)))[1:10,])
```
```{r, dataviz-4-latam}
rg$ggplotTopCountriesStackedBarDailyInc(included.countries = latam.countries, countries.text = "Latam countries")
rc$ggplotComparisonExponentialGrowth(included.countries = latam.countries, countries.text = "Latam countries",
field = "confirmed", y.label = "Confirmed", min.cases = 100)
rc$ggplotComparisonExponentialGrowth(included.countries = latam.countries, countries.text = "Latam countries",
field = "remaining.confirmed", y.label = "Active cases", min.cases = 100)
rc$ggplotComparisonExponentialGrowth(included.countries = latam.countries, field = "deaths", y.label = "Deaths", min.cases = 1)
rg$ggplotCrossSection(included.countries = latam.countries,
field.x = "confirmed",
field.y = "fatality.rate.max",
plot.description = "Cross section Confirmed vs Death rate min",
log.scale.x = TRUE,
log.scale.y = FALSE)
```
```{r, dataviz-6-latam-inc-daily}
rg$ggplotCountriesLines(included.countries = latam.countries, countries.text = "Latam countries",
field = "confirmed.inc", log.scale = TRUE)
rg$ggplotCountriesLines(included.countries = latam.countries, countries.text = "Latam countries",
field = "deaths.inc", log.scale = TRUE)
rg$ggplotCountriesLines(included.countries = latam.countries, countries.text = "Latam countries",
field = "rate.inc.daily", log.scale = TRUE)
```
```{r, dataviz-7-top-countries}
rg$ggplotTopCountriesStackedBarDailyInc(top.countries)
rc$ggplotComparisonExponentialGrowth(included.countries = international.countries,
field = "confirmed", y.label = "Confirmed", min.cases = 100)
rc$ggplotComparisonExponentialGrowth(included.countries = international.countries,
field = "remaining.confirmed", y.label = "Active cases", min.cases = 100)
rc$ggplotComparisonExponentialGrowth(included.countries = international.countries, field = "deaths",
y.label = "Deaths", min.cases = 1)
rg$ggplotCrossSection(included.countries = international.countries,
field.x = "confirmed",
field.y = "fatality.rate.max",
plot.description = "Cross section Confirmed vs Death rate min",
log.scale.x = TRUE,
log.scale.y = FALSE)
```
```{r, dataviz-8-top-countries-inc-daily}
rg$ggplotCountriesLines(field = "confirmed.inc", log.scale = TRUE)
rg$ggplotCountriesLines(field = "deaths.inc", log.scale = TRUE)
rg$ggplotCountriesLines(field = "rate.inc.daily", log.scale = TRUE)
```
```{r, dataviz-9-top-countries-legacy}
rg$ggplotTopCountriesPie()
rg$ggplotTopCountriesBarPlots()
rg$ggplotCountriesBarGraphs(selected.country = "Argentina")
```
# References
* Johns Hopkins University. Retrieved from: ‘https://github.com/CSSEGISandData/COVID-19/’ [Online Resource]
* OurWorldInData.org. Retrieved from: ‘https://ourworldindata.org/coronavirus’ [Online Resource]
Yanchang Zhao, COVID-19 Data Analysis with Tidyverse and Ggplot2 - China. RDataMining.com, 2020.
URL: http://www.rdatamining.com/docs/Coronavirus-data-analysis-china.pdf.