-
Notifications
You must be signed in to change notification settings - Fork 24
/
README.Rmd
309 lines (244 loc) · 9.53 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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
library(covid19italy)
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# covid19italy
<!-- badges: start -->
[![build](https://github.com/RamiKrispin/covid19italy/workflows/build/badge.svg?branch=master)](https://github.com/RamiKrispin/covid19italy/actions?query=workflow%3Abuild)
[![CRAN\_Status\_Badge](https://www.r-pkg.org/badges/version/covid19italy)](https://cran.r-project.org/package=covid19italy)
[![lifecycle](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![GitHub commit](https://img.shields.io/github/last-commit/RamiKrispin/covid19italy)](https://github.com/covid19r/covid19Italy/commit/master)
![Data refresh](https://github.com/RamiKrispin/covid19Italy/workflows/Data%20Refresh/badge.png)
<!-- badges: end -->
The covid19italy R package provides a tidy format dataset of the 2019 Novel Coronavirus COVID-19 (2019-nCoV) pandemic outbreak in Italy. The package includes the following three datasets:
- `italy_total` - daily summary of the outbreak on the national level
- `italy_region` - daily summary of the outbreak on the region level
- `italy_province` - daily summary of the outbreak on the province level
More information about the package datasets available [here](https://covid19r.github.io/covid19italy/articles/intro.html), and supporting dashboard available [here](https://ramikrispin.github.io/italy_dash/).
Data source: [Italy Department of Civil Protection](https://www.protezionecivile.it/)
[<img src="man/figures/Italy_province.png" width="100%" />](https://covid19r.github.io/covid19italy/articles/geospatial_visualization.html)
## Installation
You can install the released version of covid19italy from [CRAN](https://cran.r-project.org/package=covid19italy) with:
``` r
install.packages("covid19italy")
```
Or, install the most recent version from [GitHub](https://github.com/Covid19R/covid19italy) with:
``` r
# install.packages("devtools")
devtools::install_github("RamiKrispin/covid19Italy")
```
## Data refresh
While the **covid19italy** [CRAN version](https://cran.r-project.org/package=covid19italy) is updated every month or two, the [Github (Dev) version](https://github.com/RamiKrispin/covid19italy) is updated on a daily bases. The `update_data` function enables to overcome this gap and keep the installed version with the most recent data available on the Github version:
``` r
library(covid19italy)
update_data()
```
**Note:** must restart the R session to have the updates available
## Usage
```{r}
data(italy_total)
head(italy_total)
```
### Plotting the active cases distribution
``` r
library(plotly)
plot_ly(data = italy_total,
x = ~ date,
y = ~home_confinement,
name = 'Home Confinement',
fillcolor = '#FDBBBC',
type = 'scatter',
mode = 'none',
stackgroup = 'one') %>%
add_trace( y = ~ hospitalized_with_symptoms,
name = "Hospitalized with Symptoms",
fillcolor = '#E41317') %>%
add_trace(y = ~intensive_care,
name = 'Intensive Care',
fillcolor = '#9E0003') %>%
layout(title = "Italy - Distribution of Active Covid19 Cases",
legend = list(x = 0.8, y = 0.9),
yaxis = list(title = "Number of Cases"),
xaxis = list(title = "Source: Italy Department of Civil Protection"))
```
```{r include=FALSE}
library(plotly)
p <- plot_ly(data = italy_total,
x = ~ date,
y = ~home_confinement,
name = 'Home Confinement',
fillcolor = '#FDBBBC',
type = 'scatter',
mode = 'none',
stackgroup = 'one') %>%
add_trace( y = ~ hospitalized_with_symptoms,
name = "Hospitalized with Symptoms",
fillcolor = '#E41317') %>%
add_trace(y = ~intensive_care,
name = 'Intensive Care',
fillcolor = '#9E0003') %>%
layout(title = "Italy - Distribution of Active Covid19 Cases",
legend = list(x = 0.8, y = 0.9),
yaxis = list(title = "Number of Cases"),
xaxis = list(title = "Source: Italy Department of Civil Protection"))
orca(p, "man/figures/positive_dist.svg")
```
<img src="man/figures/positive_dist.svg" width="100%" />
### Plotting the daily cases distribution
```r
plot_ly(data = italy_total,
x = ~ date,
y = ~ cumulative_positive_cases,
name = 'Active',
fillcolor = '#1f77b4',
type = 'scatter',
mode = 'none',
stackgroup = 'one') %>%
add_trace( y = ~ death,
name = "Death",
fillcolor = '#E41317') %>%
add_trace(y = ~recovered,
name = 'Recovered',
fillcolor = 'forestgreen') %>%
layout(title = "Italy - Distribution of Covid19 Cases",
legend = list(x = 0.1, y = 0.9),
yaxis = list(title = "Number of Cases"),
xaxis = list(title = "Source: Italy Department of Civil Protection"))
```
```{r include=FALSE}
p <- plot_ly(data = italy_total,
x = ~ date,
y = ~ cumulative_positive_cases,
name = 'Active',
fillcolor = '#1f77b4',
type = 'scatter',
mode = 'none',
stackgroup = 'one') %>%
add_trace( y = ~ death,
name = "Death",
fillcolor = '#E41317') %>%
add_trace(y = ~recovered,
name = 'Recovered',
fillcolor = 'forestgreen') %>%
layout(title = "Italy - Distribution of Covid19 Cases",
legend = list(x = 0.1, y = 0.9),
yaxis = list(title = "Number of Cases"),
xaxis = list(title = "Source: Italy Department of Civil Protection"))
orca(p, "man/figures/case_dist.svg")
```
<img src="man/figures/case_dist.svg" width="100%" />
### Cases distribution by region
``` r
italy_region %>%
filter(date == max(date)) %>%
select(region_name, cumulative_positive_cases, recovered, death, cumulative_cases) %>%
arrange(-cumulative_cases) %>%
mutate(region = factor(region_name, levels = region_name)) %>%
plot_ly(y = ~ region,
x = ~ cumulative_positive_cases,
orientation = 'h',
text = ~ cumulative_positive_cases,
textposition = 'auto',
type = "bar",
name = "Active",
marker = list(color = "#1f77b4")) %>%
add_trace(x = ~ recovered,
text = ~ recovered,
textposition = 'auto',
name = "Recovered",
marker = list(color = "forestgreen")) %>%
add_trace(x = ~ death,
text = ~ death,
textposition = 'auto',
name = "Death",
marker = list(color = "red")) %>%
layout(title = "Cases Distribution by Region",
barmode = 'stack',
yaxis = list(title = "Region"),
xaxis = list(title = "Number of Cases"),
hovermode = "compare",
legend = list(x = 0.65, y = 0.9),
margin = list(
l = 20,
r = 10,
b = 10,
t = 30,
pad = 2
))
```
``` {r include=FALSE}
library(dplyr)
p <- italy_region %>%
filter(date == max(date)) %>%
select(region_name, cumulative_positive_cases, recovered, death, cumulative_cases) %>%
arrange(-cumulative_cases) %>%
mutate(region = factor(region_name, levels = region_name)) %>%
plot_ly(y = ~ region,
x = ~ cumulative_positive_cases,
orientation = 'h',
text = ~ cumulative_positive_cases,
textposition = 'auto',
type = "bar",
name = "Active",
marker = list(color = "#1f77b4")) %>%
add_trace(x = ~ recovered,
text = ~ recovered,
textposition = 'auto',
name = "Recovered",
marker = list(color = "forestgreen")) %>%
add_trace(x = ~ death,
text = ~ death,
textposition = 'auto',
name = "Death",
marker = list(color = "red")) %>%
layout(title = "Cases Distribution by Region",
barmode = 'stack',
yaxis = list(title = "Region"),
xaxis = list(title = "Number of Cases"),
hovermode = "compare",
legend = list(x = 0.65, y = 0.9),
margin = list(
l = 20,
r = 10,
b = 10,
t = 30,
pad = 2
))
orca(p, "man/figures/region_bar_plot.svg")
```
<img src="man/figures/region_bar_plot.svg" width="100%" />
### Cases distribution by province for Lombardia region
```r
italy_province %>%
filter(date == max(date), region_name == "Lombardia") %>%
plot_ly(labels = ~province_name, values = ~total_cases,
textinfo="label+percent",
type = 'pie') %>%
layout(title = "Lombardia - Cases Distribution by Province") %>%
hide_legend()
```
``` {r include=FALSE}
library(dplyr)
p <- italy_province %>%
filter(date == max(date), region_name == "Lombardia") %>%
plot_ly(labels = ~province_name, values = ~total_cases,
textinfo="label+percent",
type = 'pie') %>%
layout(title = "Lombardia - Cases Distribution by Province") %>%
hide_legend()
orca(p, "man/figures/province_pie.svg")
```
<img src="man/figures/province_pie.svg" width="100%" />
## Supporting Dashboard
A supporting dashboard for the **covid19italy** datasets available [here](https://ramikrispin.github.io/italy_dash/).
<img src="man/figures/dashboard.png" width="100%" />