-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathindex.Rmd
More file actions
282 lines (247 loc) · 9.41 KB
/
index.Rmd
File metadata and controls
282 lines (247 loc) · 9.41 KB
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
---
title: "COVID-19 Tracker"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
---
```{r setup, include=FALSE}
# Dependencies
library(flexdashboard)
# Functions
`%>%` <- magrittr::`%>%`
source("./dev/functions.R")
# Setting the data requirements
df <- coronavirus::refresh_coronavirus_jhu()
load("./data/gis_codes.RData")
load("./data/gis_mapping.RData")
df2 <- df %>%
dplyr::filter(location_type == "country",
!is.na(location_code),
data_type != "recovered_new") %>%
dplyr::left_join(gis_codes %>%
dplyr::select(-lat, - long) %>%
dplyr::filter(combined_key == country_region,
is.na(province_state)), by = c("location" = "combined_key")) %>%
dplyr::left_join(continent_mapping %>% dplyr::select(continent_name, continent_code, iso2), by = "iso2")
d <- df2 %>%
dplyr::filter(location_type == "country",
data_type == "cases_new") %>%
dplyr::group_by(location, continent_name) %>%
dplyr::summarise(total_cases = sum(value), .groups = "drop") %>%
dplyr::mutate(perc = 100 * total_cases / sum(total_cases)) %>%
dplyr::arrange(-total_cases)
# Fix missing values
d$continent_name[which(d$location == "South Korea")] <- "Asia"
d$continent_name[which(d$location == "Kosovo")] <- "Europe"
df3 <- df %>%
dplyr::filter(location_type == "country",
data_type != "recovered_new") %>%
dplyr::group_by(date, data_type) %>%
dplyr::summarise(total = sum(value), .groups = "drop") %>%
tidyr::pivot_wider(names_from = data_type, values_from = total)
df3$trend_new_cases <- (df3$cases_new +
dplyr::lag(df3$cases_new,1) +
dplyr::lag(df3$cases_new,2) +
dplyr::lag(df3$cases_new,3) +
dplyr::lag(df3$cases_new,4) +
dplyr::lag(df3$cases_new,5) +
dplyr::lag(df3$cases_new,6)) /7
df3$trend_deaths_cases <- (df3$deaths_new +
dplyr::lag(df3$deaths_new,1) +
dplyr::lag(df3$deaths_new,2) +
dplyr::lag(df3$deaths_new,3) +
dplyr::lag(df3$deaths_new,4) +
dplyr::lag(df3$deaths_new,5) +
dplyr::lag(df3$deaths_new,6)) /7
last_update <- paste("Last update: ", max(df$date), sep = "")
```
<script>
document.querySelector(".navbar-header > span.navbar-brand > span.navbar-author").innerHTML = "`r last_update`";
</script>
<style>
.navbar-author {
position: absolute;
right: 1rem;
}
</style>
# Summary
## Column {data-width="600"}
### Daily New Confirmed Cases - Worldwide
```{r}
highcharter::hchart(df3, "scatter", highcharter::hcaes(x = date,
y = cases_new),
name = "Daily New Cases",
color = "rgba(69, 123, 157, 0.5)",
showInLegend = TRUE) %>%
highcharter::hc_tooltip(crosshairs = TRUE, pointFormat = "Total Cases: {point.cases_new}") %>%
highcharter::hc_add_series(
df3, type = "line", highcharter::hcaes(x = date,
y = trend_new_cases),
color = "rgba(29, 53, 87, 1)",
name = "Trend Line",
id = "trend",
showInLegend = TRUE) %>%
highcharter::hc_plotOptions(
line = list(
color = "blue",
marker = list(
fillColor = "white",
lineWidth = 2,
radius=1,
lineColor = NULL
)
)
) %>%
highcharter::hc_legend( #Not in use, showInLegend = FALSE
layout = "vertical",
verticalAlign = "top",
align = "right",
floating = TRUE
) %>%
highcharter::hc_xAxis(
title = list(text = ""),
gridLineWidth = 0,
dateTimeLabelFormats = list(day = '%d/%m/%Y'),
type = "datetime",
reversed = FALSE
) %>%
highcharter::hc_yAxis(
title = list(text = "Cases"),
gridLineWidth = 0,
reversed = FALSE
) %>%
# highcharter::hc_title(
# style = list(color = highcharter::hex_to_rgba("black", 0.5)),
# text = "Daily New Confirmed Cases - Worldwide"
# ) %>%
# highcharter::hc_subtitle(
# style = list(color = hex_to_rgba("black", 0.5)),
# text = "Source: John Hopkins University"
# ) %>%
highcharter::hc_caption(text = "Trend line calculated by using 7-days moving average <br>Source: Center for Systems Science and Engineering (CSSE) at Johns Hopkins University") %>%
highcharter::hc_tooltip(
crosshairs = TRUE,
backgroundColor = "#F0F0F0",
shared = TRUE,
borderWidth = 5
)
```
### Daily Death Cases - Worldwide
```{r}
highcharter::hchart(df3, "scatter", highcharter::hcaes(x = date,
y = deaths_new),
name = "Daily Death Cases",
color = "rgba(214, 40, 40, 0.5)",
showInLegend = TRUE) %>%
highcharter::hc_tooltip(crosshairs = TRUE, pointFormat = "Total Cases: {point.deaths_new}") %>%
highcharter::hc_add_series(
df3, type = "line", highcharter::hcaes(x = date,
y = trend_deaths_cases),
color = "rgba(29, 53, 87, 1)",
name = "Trend Line",
id = "trend",
showInLegend = TRUE) %>%
highcharter::hc_plotOptions(
line = list(
color = "blue",
marker = list(
fillColor = "white",
lineWidth = 2,
radius=1,
lineColor = NULL
)
)
) %>%
highcharter::hc_legend( #Not in use, showInLegend = FALSE
layout = "vertical",
verticalAlign = "top",
align = "right",
floating = TRUE
) %>%
highcharter::hc_xAxis(
title = list(text = ""),
gridLineWidth = 0,
dateTimeLabelFormats = list(day = '%d/%m/%Y'),
type = "datetime",
reversed = FALSE
) %>%
highcharter::hc_yAxis(
title = list(text = "Cases"),
gridLineWidth = 0,
reversed = FALSE
) %>%
# highcharter::hc_title(
# style = list(color = highcharter::hex_to_rgba("black", 0.5)),
# text = "Daily Death Cases - Worldwide"
# ) %>%
# highcharter::hc_subtitle(
# style = list(color = hex_to_rgba("black", 0.5)),
# text = "Source: John Hopkins University"
# ) %>%
# highcharter::hc_caption(text = "Trend line calculated by using 7-days moving average <br>Source: Center for Systems Science and Engineering (CSSE) at Johns Hopkins University") %>%
# highcharter::hc_tooltip(
# crosshairs = TRUE,
# backgroundColor = "#F0F0F0",
# shared = TRUE,
# borderWidth = 5
# ) %>%
highcharter::hc_caption(
text = "Trend line calculated by using 7-days moving average <br>Source: Center for Systems Science and Engineering (CSSE) at Johns Hopkins University",
useHTML = TRUE
)
```
## Column {data-width="400"}
### Distribution of Total Cases by Country/Continent
```{r}
pb <- highcharter::hchart(d %>% dplyr::filter(continent_name != "Antarctica"), "packedbubble", highcharter::hcaes(name = location, value = total_cases, group = continent_name)) %>%
highcharter::hc_tooltip(
useHTML = TRUE,
pointFormat = "<b>{point.name}:</b> {point.value}"
)
q95 <- as.numeric(quantile(d$total_cases, .95))
pb %>%
highcharter::hc_plotOptions(
packedbubble = list(
maxSize = "150%",
zMin = 0,
layoutAlgorithm = list(
gravitationalConstant = 0.05,
splitSeries = TRUE, # TRUE to group points
seriesInteraction = TRUE,
dragBetweenSeries = TRUE,
parentNodeLimit = TRUE
),
dataLabels = list(
enabled = TRUE,
format = "{point.name}",
filter = list(
property = "y",
operator = ">",
value = q95
),
style = list(
color = "black",
textOutline = "none",
fontWeight = "normal"
)
)
)
)
pb
```
# About
**The COVID-19 Tracker Dashboard**
This dashboard is part of the [Deploy Flexdashboard on Github Pages with Github Actions and Docker](https://github.com/RamiKrispin/deploy-flex-actions) tutorial. This tutorial provides a step-by-step guide and a template for deploying and refreshing a [flexdashboard](https://pkgs.rstudio.com/flexdashboard/) dashboard on [Github Pages](https://pages.github.com/) with [Docker](https://www.docker.com/) and [Github Actions](https://github.com/features/actions).
**Data**
The input data for this dashboard is the [coronavirus](https://github.com/RamiKrispin/coronavirus) R package. The data and dashboard is refreshed on a daily bases. The raw data was pulled from the Johns Hopkins University Center for Systems Science and Engineering (JHU CCSE) Coronavirus [repository](https://github.com/CSSEGISandData/COVID-19).
**Packages**
The dashboard uses the following packages:
- Dashboard - [flexdashboard](https://pkgs.rstudio.com/flexdashboard/index.html)
- Data - [coronavirus](https://github.com/RamiKrispin/coronavirus)
- Data visualization - [highcharter](https://jkunst.com/highcharter/index.html)
- Utility - [dplyr](https://dplyr.tidyverse.org/), [tidyr](https://tidyr.tidyverse.org/), [lubridate](https://lubridate.tidyverse.org/)
**License**
This tutorial is licensed under a [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-nc-sa/4.0/) License.
**Connect**
For any question or feedback, you can either open an [issue](https://github.com/RamiKrispin/deploy-flex-actions/issues) or contact me on [Twitter](https://twitter.com/Rami_Krispin).