COVID-19 Virus Dashboard
This dasbhoard is designed to give a brief overview of the 2019 Novel Coronavirus COVID-19 pandemic.
Source
This dashboard makes use of the
Feedback
If you have any suggestions, comments, etc., please contact me on Twitter or file an issue.
---
title: "COVID-19"
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: fill
source_code: embed
---
```{r setup, include=FALSE}
# Load libraries
library(flexdashboard)
library(covidvirus)
library(tidyverse)
library(plotly)
library(DT)
# Acquire Data
virus <- covidvirus::get_cases(wide=T)
# define colors
clr_active = 'orange'
clr_confirmed = 'blue'
clr_dead = 'darkred'
clr_recovered = 'forestgreen'
clr_total = 'blue'
clr_overall = 'purple'
# replace NAs with zeros
virus <- virus %>%
mutate(
confirmed = ifelse(is.na(confirmed), 0, confirmed),
death = ifelse(is.na(death), 0, death),
recovered = ifelse(is.na(recovered), 0, recovered),
active = confirmed - death - recovered,
country= case_when(
country_region == 'United Arab Emirates' ~ 'UAE',
country_region == 'United States' ~ 'USA',
country_region == 'North Macedonia' ~ 'N. Macedonia',
TRUE ~ country_region
)
)
# data summaries - country
country_totals <- virus %>%
group_by(country) %>%
summarize(
confirmed = sum(confirmed),
death = sum(death),
recovered = sum(recovered),
active = sum(active)
) %>%
ungroup %>%
arrange(desc(confirmed)) %>%
mutate(country = factor(country, levels = country))
daily_totals <- virus %>%
pivot_longer(
cols = confirmed:active,
names_to = 'type',
values_to = 'cases'
) %>%
group_by(date, type) %>%
summarize(
cases = sum(cases)
) %>%
ungroup()
# data summaries - US
usdf <- virus %>%
filter(country == 'USA') %>%
select(-province_state, -city_county, -continent, -lat, -long, -country) %>%
filter(!state %in% c('Diamond Princess', 'Grand Princess'))
us_totals <- usdf %>%
group_by(state, state_name) %>%
summarize(
confirmed = sum(confirmed),
death = sum(death),
recovered = sum(recovered),
active = sum(active)
) %>%
ungroup %>%
arrange(desc(confirmed)) %>%
mutate(state = factor(state, levels = state))
us_daily <- usdf %>%
pivot_longer(
cols = confirmed:active,
names_to = 'type',
values_to = 'cases'
) %>%
group_by(date, type) %>%
summarize(
cases = sum(cases)
) %>%
ungroup()
```
Worldwide
==============
Row
-----------------------
### Countries
```{r vbox_world_cntrycount, echo = FALSE}
count_affected_countries <- country_totals %>%
filter(confirmed > 0) %>%
select(country, confirmed) %>%
distinct() %>%
count() %>%
pull(n)
valueBox(count_affected_countries, color = clr_overall)
```
### Confirmed
```{r vbox_world_confirmed, echo = FALSE}
total_confirmed = sum(country_totals$confirmed)
valueBox(total_confirmed, icon = 'fa-user-md', color = clr_total)
```
### Active Cases
```{r vbox_world_active, echo = FALSE}
active_cases = sum(country_totals$active)
pct_active = round((active_cases / total_confirmed) * 100,1)
valueBox(paste0(active_cases," (",pct_active,"%)"), icon = 'fa-hospital', color = clr_active)
```
### Recovered
```{r vbox_world_recovered, echo = FALSE}
total_recovered = sum(country_totals$recovered)
pct_recovered = round((total_recovered / total_confirmed) * 100,1)
valueBox(paste0(total_recovered," (",pct_recovered,"%)"), icon = 'fa-walking', color = clr_recovered)
```
### Deaths
```{r vbox_world_deaths, echo = FALSE}
total_deaths = sum(country_totals$death)
pct_dead = round((total_deaths / total_confirmed) * 100, 1)
valueBox(paste0(total_deaths," (", pct_dead, "%)"), icon = 'fa-dizzy', color = clr_dead)
```
Row
-----------------------------------------------------------------------
### Active Cases - Worldwide
```{r map_world_choropleth, echo = FALSE}
# specify map projection/options
g <- list(
showframe = FALSE,
showcoastlines = TRUE,
projection = list(type = 'Robinson')
)
country_totals2 <- country_totals %>%
mutate(
hover = paste0(country, '
', 'Confirmed cases: ', confirmed, '
', 'Deaths: ', death, '
', 'Recovered: ', recovered)
)
plot_geo(country_totals2) %>%
add_trace(
z = ~active, locations = ~country,
text = ~hover,
locationmode = 'country names',
color = ~active,
colors = 'Oranges'
) %>%
colorbar(title = 'Active Cases', limits = c(0, max(country_totals$active)), len = 1) %>%
layout(
#title = 'Active Covid-19 Virus Cases Worldwide
(Hover for breakdown)',
geo = g,
autosize = T
)
```
USA
=================================
Row
--------------
### States & Territories
```{r vbox_usa_statecount, echo = FALSE}
state_count = usdf %>% filter(confirmed > 0 & !state %in% c('Diamond Princess','Grand Princess') & !is.na(state)) %>% select(state) %>% distinct() %>% count()
valueBox(value = state_count, color = clr_overall)
```
### Confirmed
```{r vbox_usa_confirmed, echo = FALSE}
us_confirmed = sum(usdf$confirmed)
valueBox(us_confirmed, icon = 'fa-user-md', color = clr_total)
```
### Active
```{r vbox_usa_active, echo = FALSE}
us_active_cases = sum(usdf$active)
us_pct_active = round((us_active_cases / us_confirmed) * 100,1)
valueBox(paste0(us_active_cases," (",us_pct_active,"%)"), icon = 'fa-hospital', color = clr_active)
```
### Recovered
```{r vbox_usa_recovered, echo = FALSE}
us_recovered = sum(usdf$recovered)
us_pct_recovered = round((us_recovered / us_confirmed) * 100,1)
valueBox(paste0(us_recovered," (",us_pct_recovered,"%)"), icon = 'fa-walking', color = clr_recovered)
```
### Deaths
```{r vbox_usa_deaths, echo = FALSE}
us_deaths = sum(usdf$death)
us_pct_dead = round((us_deaths / us_confirmed) * 100, 1)
valueBox(paste0(us_deaths," (", us_pct_dead, "%)"), icon = 'fa-dizzy', color = clr_dead)
```
Row
----------------------
### Active Cases - USA
```{r map_us_choropleth, echo = FALSE}
us2 <- us_totals %>%
mutate(
hover = paste0(state_name, '
', 'confirmed cases: ', confirmed, '
', 'Deaths: ', death, '
', 'Recovered: ', recovered)
)
max_cases <- us_totals %>%
filter(!is.na(state)) %>%
filter(!state %in% c('Guam','Puerto Rico','Virgin Islands')) %>%
summarize(
max_case_count = max(active)
) %>%
pull(max_case_count)
g2 <- list(
scope = 'usa',
projection = list(type = 'albers usa'),
showlakes = TRUE,
lakecolor = toRGB('white')
)
fig <- plot_geo(us2, locationmode = 'USA-states') %>%
add_trace(
z = ~active, text = ~hover, locations = ~state,
color = ~active, colors = 'Oranges'
) %>%
layout(
geo = g2
) %>%
colorbar(title = "Active Cases", limits = c(0, max_cases) , len = 1)
config(fig, fillFrame = TRUE)
# bug fix solution: https://github.com/ropensci/plotly/issues/1546 ; see solution by cpsievert on Aug. 30, 2019
```
Trends
===============================
Row
----------------------
### Daily Cumulative Cases by Type - Worldwide
```{r trends_worldwide, echo = FALSE}
dailies <- daily_totals %>%
pivot_wider(
names_from = type,
values_from = cases,
values_fill = list(cases = 0)
) %>%
arrange(date) %>%
mutate(
total_active = cumsum(active),
total_confirmed = cumsum(confirmed),
total_dead = cumsum(death),
total_recovered = cumsum(recovered)
) %>%
select(-active, -confirmed, -death, -recovered)
plot_ly(data = dailies, x = ~date, y = ~total_active, name='Active', type = 'scatter', mode = 'lines+markers', line = list(color = clr_active), marker = list(color = clr_active)) %>%
add_trace(y = ~total_dead, name = 'Dead', type = 'scatter', mode = 'lines+markers', line = list(color = clr_dead), marker = list(color = clr_dead)) %>%
add_trace(y = ~total_recovered, name = 'Recovered', type = 'scatter', mode = 'lines+markers', line = list(color= clr_recovered), marker = list(color=clr_recovered)) %>%
layout(yaxis = list(title = 'Cumulative Total Cases (log scale)', type = 'log'), xaxis = list(title = 'Date'))
```
### Daily Cumulative Cases by Type - USA
```{r trends_usa, echo=FALSE}
us_dailies <- us_daily %>%
pivot_wider(
names_from = type,
values_from = cases,
values_fill = list(cases = 0)
) %>%
arrange(date) %>%
mutate(
total_active = cumsum(active),
total_confirmed = cumsum(confirmed),
total_dead = cumsum(death),
total_recovered = cumsum(recovered)
) %>%
select(-active, -confirmed, -death, -recovered)
plot_ly(data = us_dailies, x = ~date, y = ~total_active, name='Active', type = 'scatter', mode = 'lines+markers', line = list(color = clr_active), marker = list(color = clr_active)) %>%
add_trace(y = ~total_dead, name = 'Dead', type = 'scatter', mode = 'lines+markers', line = list(color = clr_dead), marker = list(color = clr_dead)) %>%
add_trace(y = ~total_recovered, name = 'Recovered', type = 'scatter', mode = 'lines+markers', line = list(color= clr_recovered), marker = list(color=clr_recovered)) %>%
layout(yaxis = list(title = 'Cumulative Total Cases (log scale)', type = 'log'))
```
Row
-----------
### Active, Recovery, & Death Rates by Country (minimum 50 confirmed cases)
```{r tbl_world, echo=FALSE}
country_rates <- country_totals %>%
mutate(
active_pct = round((active / confirmed)*100,1),
dead_pct = round((death / confirmed) * 100, 1),
recover_pct = round((recovered / confirmed) * 100, 1)
) %>%
arrange(desc(confirmed)) %>%
select(country = country, confirmed, active_pct, dead_pct, recover_pct) %>%
filter(confirmed >= 50)
datatable(country_rates,
rownames = F,
colnames = c("Country", "Confirmed", "Active Rate", "Death Rate", "Recovery Rate"),
options = list(dom = 'tip')
)
```
### Active, Recovery, & Death Rates by State
```{r tbl_USA, echo=FALSE}
state_rates <- us_totals %>%
mutate(
active_pct = round((active / confirmed)*100,1),
dead_pct = round((death / confirmed) * 100, 1),
recover_pct = round((recovered / confirmed) * 100, 1)
) %>%
arrange(desc(confirmed)) %>%
select(state, confirmed, active_pct, dead_pct, recover_pct) %>%
filter(confirmed > 0 & !is.na(state))
datatable(state_rates,
rownames = F,
colnames = c("State", "Confirmed", "Active Rate", "Death Rate", "Recovery Rate"),
options = list(dom = 'tip')
)
```
About
=============
**COVID-19 Virus Dashboard**
This dasbhoard is designed to give a brief overview of the 2019 Novel Coronavirus COVID-19 pandemic.
**Source**
This dashboard makes use of the [](https://github.com/nikdata/covidvirus) R package. The underlying data comes from Johns Hopkins University Center for Systems Science and Engineering (JHU CCSE) Coronavirus [repository](https://github.com/CSSEGISandData/COVID-19)
**Feedback**
If you have any suggestions, comments, etc., please contact me on [Twitter](www.twitter.com/nikagarwal) or file an issue.