TOC { position: fixed; left: 0; top: 0; width: 200px; height: 100%; overflow:auto; }

################################################################################
##   Covid-19 dashboard: the cases of USA & Germany
##        by Dr. Jimmy Zhenning Xu, 
##    follow me on Twitter https://twitter.com/MKTJimmyxu
################################################################################

=======================================================================

Introduction to the dashboard

The data and dashboard are refreshed on a daily basis.

This “Covid-19 dashboard: the cases of USA & Germany” provides an overview of the 2019 Novel Coronavirus COVID-19 (2019-nCoV) epidemic for the US. and Germany. This dashboard is built with R using the R Makrdown framework and was developed using the coronavirus package.

Why the USA & Germany?

The purpose of this dashboard is to show you that different lockdown policies may have different consequences. News reports suggest that Germany is one of the countries that implemented the most strict lockdown policies. In the United States, the lockdown policies tend to be drastically different across different stats.

Dataset

The input data for this dashboard is the dataset available from the R package, coronavirus. You can download the development version of the package to have the latest data:

install.packages(“devtools”) devtools::install_github(“RamiKrispin/coronavirus”)

The raw data is pulled from the Johns Hopkins University Center for Systems Science and Engineering (JHU CCSE) Coronavirus repository.

Figure 1 - Daily cumulative cases and deaths (USA only)

Please find the figure under the code snippet.

library(flexdashboard)
## Warning: package 'flexdashboard' was built under R version 3.6.3
library(coronavirus)
data(coronavirus)


`%>%` <- magrittr::`%>%`

df_dailyUSA <- coronavirus %>%
  dplyr::filter(Country.Region == "US") %>%
  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 - recovered) %>%
  dplyr::mutate(active = confirmed - death) %>%
  dplyr::mutate(
    confirmed_cum = cumsum(confirmed),
    death_cum = cumsum(death),
    # recovered_cum = cumsum(recovered),
    active_cum = cumsum(active)
  )

tail(df_dailyUSA)
## # A tibble: 6 x 8
##   date       confirmed death recovered active confirmed_cum death_cum active_cum
##   <date>         <int> <int>     <int>  <int>         <int>     <int>      <int>
## 1 2020-05-03     25501  1313      4770  24188       1158040     67682    1090358
## 2 2020-05-04     22335  1240      7028  21095       1180375     68922    1111453
## 3 2020-05-05     23976  2142      2611  21834       1204351     71064    1133287
## 4 2020-05-06     24252  2367       119  21885       1228603     73431    1155172
## 5 2020-05-07     28420  2231      5126  26189       1257023     75662    1181361
## 6 2020-05-08     26906  1518      3957  25388       1283929     77180    1206749
# https://www.w3.org/TR/css-color-3/#svg-color
confirmed_color <- "purple"
active_color <- "#1f77b4"
recovered_color <- "forestgreen"
death_color <- "red"


plotly::plot_ly(data = df_dailyUSA) %>%
  plotly::add_trace(
    x = ~date,
    # y = ~active_cum,
    y = ~confirmed_cum,
    type = "scatter",
    mode = "lines+markers",
    # name = "Active",
    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-02-04"),
    y = 1,
    text = paste("1st case"),
    xref = "x",
    yref = "y",
    arrowhead = 5,
    arrowhead = 3,
    arrowsize = 1,
    showarrow = TRUE,
    ax = -10,
    ay = -90
  ) %>%
  plotly::add_annotations(
    x = as.Date("2020-02-29"),
    y = 3,
    text = paste("1st 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-19"),
    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"
  )

Figure 2 -Daily cumulative cases and deaths (Germany only)

Please find the figure under the code snippet.

library(flexdashboard)
library(coronavirus)
data(coronavirus)

`%>%` <- magrittr::`%>%`

df_dailyGermany <- coronavirus %>%
  dplyr::filter(Country.Region == "Germany") %>%
  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 - recovered) %>%
  dplyr::mutate(active = confirmed - death) %>%
  dplyr::mutate(
    confirmed_cum = cumsum(confirmed),
    death_cum = cumsum(death),
    # recovered_cum = cumsum(recovered),
    active_cum = cumsum(active)
  )

# https://www.w3.org/TR/css-color-3/#svg-color
confirmed_color <- "purple"
active_color <- "#1f77b4"
recovered_color <- "forestgreen"
death_color <- "red"


plotly::plot_ly(data = df_dailyGermany) %>%
  plotly::add_trace(
    x = ~date,
    # y = ~active_cum,
    y = ~confirmed_cum,
    type = "scatter",
    mode = "lines+markers",
    # name = "Active",
    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-01-28"),
    y = 1,
    text = paste("1st case"),
    xref = "x",
    yref = "y",
    arrowhead = 5,
    arrowhead = 3,
    arrowsize = 1,
    showarrow = TRUE,
    ax = -10,
    ay = -90
  ) %>%
  plotly::add_annotations(
    x = as.Date("2020-03-09"),
    y = 3,
    text = paste("1st 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-22"),
    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"
  )

Table - Comparing updated cases and deaths between the US and Germany

This section shows two tables featuring the updated cases and deaths for the most recent 6 days between the US and Germany. The table is refreshed on a daily basis.

tail(df_dailyUSA)
## # A tibble: 6 x 8
##   date       confirmed death recovered active confirmed_cum death_cum active_cum
##   <date>         <int> <int>     <int>  <int>         <int>     <int>      <int>
## 1 2020-05-03     25501  1313      4770  24188       1158040     67682    1090358
## 2 2020-05-04     22335  1240      7028  21095       1180375     68922    1111453
## 3 2020-05-05     23976  2142      2611  21834       1204351     71064    1133287
## 4 2020-05-06     24252  2367       119  21885       1228603     73431    1155172
## 5 2020-05-07     28420  2231      5126  26189       1257023     75662    1181361
## 6 2020-05-08     26906  1518      3957  25388       1283929     77180    1206749
tail(df_dailyGermany)
## # A tibble: 6 x 8
##   date       confirmed death recovered active confirmed_cum death_cum active_cum
##   <date>         <int> <int>     <int>  <int>         <int>     <int>      <int>
## 1 2020-05-03       697    54      1600    643        165664      6866     158798
## 2 2020-05-04       488   127      2100    361        166152      6993     159159
## 3 2020-05-05       855     0      2400    855        167007      6993     160014
## 4 2020-05-06      1155   282      4800    873        168162      7275     160887
## 5 2020-05-07      1268   117      1800   1151        169430      7392     162038
## 6 2020-05-08      1158   118         0   1040        170588      7510     163078

References

COVID19.Analytics https://cran.r-project.org/web/packages/covid19.analytics/vignettes/covid19.analytics.html

Coronavirus Death in California Came Weeks Before First Known U.S. Death https://www.nytimes.com/2020/04/22/us/coronavirus-first-united-states-death.html

National responses to the COVID-19 pandemic https://en.wikipedia.org/wiki/National_responses_to_the_COVID-19_pandemic#United_States

Transmission of 2019-nCoV Infection from an Asymptomatic Contact in Germany https://www.nejm.org/doi/full/10.1056/NEJMc2001468

Germany lockdown: When did Germany go on lockdown? Why is Germany death rate so low? https://www.express.co.uk/news/world/1270472/Germany-lockdown-when-did-Germany-go-on-lockdown-why-is-Germany-death-rate-so-low

Germany Reports First Two Deaths From Coronavirus Outbreak https://www.bloomberg.com/news/articles/2020-03-09/germany-reports-first-death-from-coronavirus-outbreak-dpa-says