424,295
18,205 (4.3%)
The COVID-19 Dashboard
This dashboard provides an overview of the Novel Coronavirus (COVID-19 / SARS-CoV-2) epidemic for Bulgaria and its surrounding countries. This dashboard is built with R using the R Makrdown and flexdashboard framework and was adapted from the dashboard of Rami Krispin, courtesy of Antoine Soetewey.
Code
The code for the dashboard is available on GitHub.
Packages
Data
The input data for this dashboard is the dataset available from the {coronavirus} R package.
The raw data is pulled from the Johns Hopkins University Center for Systems Science and Engineering (JHU CCSE) Coronavirus repository.
---
title: "COVID-19 in Bulgaria"
author: "Metodi Simeonov"
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: fill
source_code: embed
---
```{r setup, include=FALSE}
library(flexdashboard)
#install.packages("htmltools")
#devtools::install_github("RamiKrispin/coronavirus", force = TRUE)
library(coronavirus)
data(coronavirus)
`%>%` <- magrittr::`%>%`
#------------------ Parameters ------------------
# Set colors - https://www.w3.org/TR/css-color-3/#svg-color
confirmed_color <- "#4682B4"
active_color <- "#1f77b4"
recovered_color <- "deepskyblue"
death_color <- "#451208"
#------------------ Data ------------------
df <- coronavirus %>%
dplyr::filter(country == "Bulgaria") %>%
dplyr::group_by(country, type) %>%
dplyr::summarise(total = sum(cases)) %>%
tidyr::pivot_wider(
names_from = type,
values_from = total
) %>%
dplyr::mutate(unrecovered = confirmed - ifelse(is.na(death), 0, death)) %>%
dplyr::arrange(-confirmed) %>%
dplyr::ungroup() %>%
dplyr::mutate(country = dplyr::if_else(country == "North Macedonia", "N.Macedonia", country)) %>%
dplyr::mutate(country = trimws(country)) %>%
dplyr::mutate(country = factor(country, levels = country))
df_daily <- coronavirus %>%
dplyr::filter(country == "Bulgaria") %>%
dplyr::group_by(date, type) %>%
dplyr::summarise(total = sum(cases, na.rm = TRUE)) %>%
tidyr::pivot_wider(
names_from = type,
values_from = total
) %>%
dplyr::arrange(date) %>%
dplyr::ungroup() %>%
dplyr::mutate(active = confirmed - death) %>%
dplyr::mutate(
confirmed_cum = cumsum(confirmed),
death_cum = cumsum(death),
active_cum = cumsum(active)
)
df1 <- coronavirus %>% dplyr::filter(date == max(date))
df_tree <- coronavirus %>%
dplyr::filter(country == "Bulgaria" | country == "Romania" | country == "Greece" | country == "Serbia" | country == "North Macedonia") %>%
dplyr::group_by(country, type) %>%
dplyr::summarise(total = sum(cases), .groups = "drop") %>%
dplyr::mutate(type = ifelse(type == "confirmed", "Confirmed", type),
type = ifelse(type == "recovered", "Recovered", type),
type = ifelse(type == "death", "Death", type)) %>%
tidyr::pivot_wider(names_from = type, values_from = total) %>%
dplyr::mutate(Active = Confirmed - Death - Recovered) %>%
tidyr::pivot_longer(cols = -country, names_to = "type", values_to = "total")
```
Summary Tab
=====================================
Row {data-width=350}
-----------------------------------------------------------------------
### Confirmed cases {.value-box}
```{r}
valueBox(
value = paste(format(sum(df$confirmed), big.mark = ","), "", sep = " "),
caption = "Total Confirmed Cases",
icon = "fas fa-user-md",
color = confirmed_color
)
```
### Deaths {.value-box}
```{r}
valueBox(
value = paste(format(sum(df$death, na.rm = TRUE), big.mark = ","), " (",
round(100 * sum(df$death, na.rm = TRUE) / sum(df$confirmed), 1),
"%)",
sep = ""
),
caption = "Death Cases / Death Rate",
icon = "fa-cross",
color = death_color
)
```
Column {data-width=400}
-------------------------------------
### **Daily Cumulative Cases by Type** (Bulgaria only)
```{r}
plotly::plot_ly(data = df_daily) %>%
plotly::add_trace(
x = ~date,
y = ~confirmed_cum,
type = "scatter",
mode = "lines+markers",
name = "Confirmed",
line = list(color = active_color),
marker = list(color = active_color)
) %>%
plotly::add_trace(
x = ~date,
y = ~death_cum,
type = "scatter",
mode = "lines+markers",
name = "Death",
line = list(color = death_color),
marker = list(color = death_color)
) %>%
plotly::add_annotations(
x = as.Date("2020-03-11"),
y = 3,
text = paste("First Death"),
xref = "x",
yref = "y",
arrowhead = 5,
arrowhead = 3,
arrowsize = 1,
showarrow = TRUE,
ax = -90,
ay = -90
) %>%
plotly::add_annotations(
x = as.Date("2020-03-13"),
y = 14,
text = paste(
"Lockdown"
),
xref = "x",
yref = "y",
arrowhead = 5,
arrowhead = 3,
arrowsize = 1,
showarrow = TRUE,
ax = -10,
ay = -90
) %>%
plotly::layout(
title = "",
yaxis = list(title = "Cumulative Number of Cases"),
xaxis = list(title = "Date"),
legend = list(x = 0.1, y = 0.9),
hovermode = "compare"
)
```
Row {.tabset}
-----------------------------------------------------------------------
### Cases Distribution by Type
```{r daily_summary}
plotly::plot_ly(
data = df_tree %>% dplyr::filter(type == "Confirmed"),
type= "treemap",
values = ~total,
labels= ~ country,
parents= ~type,
domain = list(column=0),
name = "Confirmed",
textinfo="label+value+percent parent"
) %>%
plotly::add_trace(
data = df_tree %>% dplyr::filter(type == "Active"),
type= "treemap",
values = ~total,
labels= ~ country,
parents= ~type,
domain = list(column=1),
name = "Active",
textinfo="label+value+percent parent"
) %>%
plotly::add_trace(
data = df_tree %>% dplyr::filter(type == "Recovered"),
type= "treemap",
values = ~total,
labels= ~ country,
parents= ~type,
domain = list(column=2),
name = "Recovered",
textinfo="label+value+percent parent"
) %>%
plotly::add_trace(
data = df_tree %>% dplyr::filter(type == "Death"),
type= "treemap",
values = ~total,
labels= ~ country,
parents= ~type,
domain = list(column=3),
name = "Death",
textinfo="label+value+percent parent"
) %>%
plotly::layout(grid=list(columns=4, rows=1))
```
Comparison by Country
=======================================================================
Row {data-width=350}
-------------------------------------
### **Daily New Confirmed Cases**
```{r}
daily_confirmed <- coronavirus %>%
dplyr::filter(type == "confirmed") %>%
dplyr::filter(date >= "2020-03-07") %>%
dplyr::mutate(country = country) %>%
dplyr::group_by(date, country) %>%
dplyr::summarise(total = sum(cases)) %>%
dplyr::ungroup() %>%
tidyr::pivot_wider(names_from = country, values_from = total)
#----------------------------------------
# Plotting the data
daily_confirmed %>%
plotly::plot_ly() %>%
plotly::add_trace(
x = ~date,
y = ~Bulgaria,
type = "scatter",
mode = "lines+markers",
name = "Bulgaria"
) %>%
plotly::add_trace(
x = ~date,
y = ~Romania,
type = "scatter",
mode = "lines+markers",
name = "Romania"
) %>%
plotly::add_trace(
x = ~date,
y = ~`North Macedonia`,
type = "scatter",
mode = "lines+markers",
name = "N.Macedonia"
) %>%
plotly::add_trace(
x = ~date,
y = ~Serbia,
type = "scatter",
mode = "lines+markers",
name = "Serbia"
) %>%
plotly::add_trace(
x = ~date,
y = ~Greece,
type = "scatter",
mode = "lines+markers",
name = "Greece"
) %>%
plotly::layout(
title = "",
legend = list(x = 1, y = 0.9),
yaxis = list(title = "New confirmed cases"),
xaxis = list(title = "Date"),
hovermode = "compare",
margin = list(
b = 10,
t = 10,
pad = 2
)
)
```
Row
-------------------------------------
### **Cases Distribution by Type**
```{r}
df_EU <- coronavirus %>%
dplyr::filter(country == "Bulgaria" |
country == "North Macedonia" |
country == "Romania" |
country == "Serbia" |
country == "Greece") %>%
dplyr::group_by(country, type) %>%
dplyr::summarise(total = sum(cases)) %>%
tidyr::pivot_wider(
names_from = type,
values_from = total
) %>%
dplyr::mutate(unrecovered = confirmed - ifelse(is.na(death), 0, death)) %>%
dplyr::arrange(confirmed) %>%
dplyr::ungroup() %>%
dplyr::mutate(country = dplyr::if_else(country == "North Macedonia", "N.Macedonia", country)) %>%
dplyr::mutate(country = trimws(country)) %>%
dplyr::mutate(country = factor(country, levels = country))
plotly::plot_ly(
data = df_EU,
x = ~country,
y = ~ confirmed,
type = "bar",
name = "Confirmed",
marker = list(color = active_color)
) %>%
plotly::add_trace(
y = ~death,
name = "Death",
marker = list(color = death_color)
) %>%
plotly::layout(
barmode = "stack",
yaxis = list(title = "Total cases"),
xaxis = list(title = ""),
hovermode = "compare",
margin = list(
b = 10,
t = 10,
pad = 2
)
)
```
### **Recovery / Death Ratio**
```{r}
coronavirus %>%
dplyr::filter(country == "Bulgaria" | country == "Romania" | country == "Greece" | country == "North Macedonia") %>%
dplyr::group_by(country, type) %>%
dplyr::summarise(total_cases = sum(cases)) %>%
tidyr::pivot_wider(names_from = type, values_from = total_cases) %>%
dplyr::arrange(- confirmed) %>%
dplyr::mutate(recover_rate = recovered / confirmed,
death_rate = death / confirmed) %>%
dplyr::mutate(recover_rate = dplyr::if_else(is.na(recover_rate), 0, recover_rate),
death_rate = dplyr::if_else(is.na(death_rate), 0, death_rate)) %>%
dplyr::ungroup() %>%
dplyr::mutate(confirmed_normal = as.numeric(confirmed) / max(as.numeric(confirmed))) %>%
plotly::plot_ly(y = ~ round(100 * recover_rate, 1),
x = ~ round(100 * death_rate, 1),
size = ~ log(confirmed),
sizes = c(5, 70),
type = 'scatter', mode = 'markers',
color = ~ country,
marker = list(sizemode = 'diameter' , opacity = 0.5),
hoverinfo = 'text',
text = ~paste("", country,
" Confirmed Cases: ", confirmed,
" Recovery Rate: ", paste(round(100 * recover_rate, 1), "%", sep = ""),
" Death Rate: ", paste(round(100 * death_rate, 1), "%", sep = ""))
) %>%
plotly::layout(yaxis = list(title = "Recovery Rate", ticksuffix = "%"),
xaxis = list(title = "Death Rate", ticksuffix = "%",
dtick = 1,
tick0 = 0),
hovermode = "compare")
```
World Map
=======================================================================
Column {data-width=400}
-------------------------------------
### **World map of cases** (*use + and - icons to zoom in/out*)
```{r}
# map tab added by Art Steinmetz
library(leaflet)
library(leafpop)
library(purrr)
cv_data_for_plot <- coronavirus %>%
# dplyr::filter(country == "Bulgaria") %>%
dplyr::filter(cases > 0) %>%
dplyr::group_by(country, province, lat, long, type) %>%
dplyr::summarise(cases = sum(cases)) %>%
dplyr::mutate(log_cases = 2 * log(cases)) %>%
dplyr::ungroup()
cv_data_for_plot.split <- cv_data_for_plot %>% split(cv_data_for_plot$type)
pal <- colorFactor(c("#4682B4", "#451208", "#02c48d"), domain = c("confirmed", "death", "recovered"))
map_object <- leaflet() %>% addProviderTiles(providers$Stamen.Toner)
names(cv_data_for_plot.split) %>%
purrr::walk(function(df) {
map_object <<- map_object %>%
addCircleMarkers(
data = cv_data_for_plot.split[[df]],
lng = ~long, lat = ~lat,
# label=~as.character(cases),
color = ~ pal(type),
stroke = FALSE,
fillOpacity = 0.6,
radius = ~log_cases,
popup = leafpop::popupTable(cv_data_for_plot.split[[df]],
feature.id = FALSE,
row.numbers = FALSE,
zcol = c("type", "cases", "country", "province")
),
group = df,
# clusterOptions = markerClusterOptions(removeOutsideVisibleBounds = F),
labelOptions = labelOptions(
noHide = F,
direction = "auto"
)
)
})
map_object %>%
addLayersControl(
overlayGroups = names(cv_data_for_plot.split),
options = layersControlOptions(collapsed = FALSE)
)
```
About
=======================================================================
**The COVID-19 Dashboard**
This dashboard provides an overview of the Novel Coronavirus (COVID-19 / SARS-CoV-2) epidemic for Bulgaria and its surrounding countries. This dashboard is built with R using the R Makrdown and flexdashboard framework and was adapted from the dashboard of [Rami Krispin](https://ramikrispin.github.io){target="_blank"}, courtesy of [Antoine Soetewey](https://github.com/AntoineSoetewey){target="_blank"}.
**Code**
The code for the dashboard is available on [GitHub](https://github.com/Met0o/COVID){target="_blank"}.
**Packages**
* Dashboard interface - [flexdashboard](https://rmarkdown.rstudio.com/flexdashboard/)
* Visualization - [plotly](https://plot.ly/r/)
* Data manipulation - [dplyr](https://dplyr.tidyverse.org/), [tidyr](https://tidyr.tidyverse.org/), and [purrr](https://purrr.tidyverse.org/)
* Mapping - [leaflet](https://rstudio.github.io/leaflet/) and [leafpop](https://github.com/r-spatial/leafpop)
**Data**
The input data for this dashboard is the dataset available from the [`{coronavirus}`](https://github.com/RamiKrispin/coronavirus){target="_blank"} R package.
The raw data is pulled from the Johns Hopkins University Center for Systems Science and Engineering (JHU CCSE) Coronavirus [repository](https://github.com/RamiKrispin/coronavirus-csv){target="_blank"}.