Summary

Row

confirmed

163,312

death

1,298 (0.8%)

Row

Daily cumulative cases by type (Denmark only)

Comparison

Daily new confirmed deaths - moving average

R - values

Column

Denmark

Sweden

Development

Column

Denmark - new positive

Sweden - new positive

About

The Coronavirus Dashboard: the case of Denmark

This Coronavirus dashboard: the case of Denmark provides an overview of the 2019 Novel Coronavirus COVID-19 (2019-nCoV) epidemic for Denmark. This dashboard is built with R using the R Makrdown framework and was adapted from this dashboard by Rami Krispin.

Code

The code behind this dashboard is available on GitHub.

Data

The data and dashboard are refreshed on a daily basis.

The raw data is pulled from the ECDC read.csv(“https://opendata.ecdc.europa.eu/covid19/casedistribution/csv”, na.strings = "“, fileEncoding =”UTF-8-BOM").

Information

More information about this dashboard (and how to replicate it for your own country) can be found in this article.

Update

The data is as of Fredag Januar 01, 2021 and the dashboard has been updated on Fredag Januar 01, 2021.

Go back to www.statsandr.com (blog) or www.antoinesoetewey.com (personal website).

---
title: "Coronavirus in Denmark"
author: "Christian Heebøll-Nielsen"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    social: ["facebook", "twitter", "linkedin"]
    source_code: embed
    vertical_layout: fill
---

```{r setup, include=FALSE,}
knitr::opts_chunk$set(echo = FALSE)
#------------------ Packages ------------------
#devtools::install_github("RamiKrispin/coronavirus", force = TRUE)
library(flexdashboard)
library(lubridate)
library(ggplot2)
library(MASS)
library(magrittr)
library(dplyr)
library(zoo)
library(easynls) 
library(readxl)
library(plotly)
library(growthmodels)
library(tidyr)
library(R0)
library(readr)
library(stringr)

data <-read.csv("https://covid.ourworldindata.org/data/owid-covid-data.csv", 
                 na.strings = "", fileEncoding = "UTF-8-BOM")

data$date <- as.Date(data$date)

`%>%` <- magrittr::`%>%`
#------------------ Parameters ------------------
# Set colors
# https://www.w3.org/TR/css-color-3/#svg-color
confirmed_color <- "purple"
active_color <- "#1f77b4"
recovered_color <- "forestgreen"
death_color <- "red"
#------------------ Data ------------------
df <- data %>%
  dplyr::filter(!is.na(new_cases)) %>%
  dplyr::filter(!is.na(new_deaths)) %>%
  dplyr::filter(location == "Denmark") %>%
  dplyr::summarise(total_cases = sum(new_cases), total_deaths = sum(new_deaths))
  
df_daily <- data %>%
  dplyr::filter(!is.na(new_cases)) %>%
  dplyr::filter(!is.na(new_deaths)) %>%
  dplyr::filter(location == "Denmark") %>%
  dplyr::arrange(date) %>%
  dplyr::mutate(
    confirmed_cum = cumsum(new_cases),
    death_cum = cumsum(new_deaths),
  )


df1 <- data %>% dplyr::filter(date == max(date))
```

Summary
=======================================================================

Row {data-width=400}
-----------------------------------------------------------------------

### confirmed {.value-box}

```{r}

 valueBox(
  value = paste(format(sum(df$total_cases), big.mark = ","), "", sep = " "),
  caption = "Total confirmed cases",
  icon = "fas fa-user-md",
  color = confirmed_color
  )
```


### death {.value-box}

```{r}

valueBox(
  value = paste(format(sum(df$total_deaths, na.rm = TRUE), big.mark = ","), " (",
    round(100 * sum(df$total_deaths, na.rm = TRUE) / sum(df$total_cases), 1),
    "%)",
    sep = ""
  ),
  caption = "Death cases (death rate)",
  icon = "fas fa-heart-broken",
  color = death_color
)
```


Row
-----------------------------------------------------------------------

### **Daily cumulative cases by type** (Denmark only)
    
```{r}
plotly::plot_ly(data = df_daily) %>%
  plotly::add_trace(
    x = ~date,
    y = ~confirmed_cum,
    type = "scatter",
    mode = "lines+markers",
    # name = "Active",
    name = "Confirmed", secondary_y = FALSE,
    line = list(color = active_color),
    marker = list(color = active_color),
    yaxis = 'y'
  ) %>%
  plotly::add_trace(
    x = ~date,
    y = ~death_cum,
    type = "scatter",
    mode = "lines+markers",
    name = "Death", secondary_y = TRUE,
    line = list(color = death_color),
    marker = list(color = death_color),
    yaxis = 'y2'
  ) %>%
  plotly::add_annotations(
    x = as.Date("2020-02-27"),
    y = 1,
    text = paste("First 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-14"),
    y = 3,
    text = paste("First death"),
    xref = "x",
    yref = "y",
    arrowhead = 5,
    arrowhead = 3,
    arrowsize = 1,
    showarrow = TRUE,
    ax = -90,
    ay = -50
  ) %>%
  plotly::add_annotations(
    x = as.Date("2020-03-18"),
    y = 14,
    text = paste(
      "Lockdown"
    ),
    xref = "x",
    yref = "y",
    arrowhead = 5,
    arrowhead = 3,
    arrowsize = 1,
    showarrow = TRUE,
    ax = -30,
    ay = -90
  ) %>%
  plotly::add_annotations(
    x = as.Date("2020-04-15"),
    y = 14,
    text = paste(
      "Schools reopen"
    ),
    xref = "x",
    yref = "y",
    arrowhead = 5,
    arrowhead = 3,
    arrowsize = 1,
    showarrow = TRUE,
    ax = -90,
    ay = -50
  ) %>%
  plotly::add_annotations(
    x = as.Date("2020-04-20"),
    y = 14,
    text = paste(
      "Reopening liberal business"
    ),
    xref = "x",
    yref = "y",
    arrowhead = 5,
    arrowhead = 3,
    arrowsize = 1,
    showarrow = TRUE,
    ax = 0,
    ay = -70
  ) %>%
  plotly::add_annotations(
    x = as.Date("2020-05-11"),
    y = 14,
    text = paste(
      "Reopening retail"
    ),
    xref = "x",
    yref = "y",
    arrowhead = 5,
    arrowhead = 3,
    arrowsize = 1,
    showarrow = TRUE,
    ax = 10,
    ay = -50
  ) %>%
  plotly::add_annotations(
    x = as.Date("2020-05-18"),
    y = 14,
    text = paste(
    "Older children back to school, churches, libraries, cafes, restaurants "
    ),
    xref = "x",
    yref = "y",
    arrowhead = 5,
    arrowhead = 3,
    arrowsize = 1,
    showarrow = TRUE,
    ax = 50,
    ay = 50
  ) %>%
  plotly::layout(
    title = "",
    yaxis = list(title = "Cumulative number of cases"),
    yaxis2 = list(overlaying = "y", side = "right", position = 0.95, title = "Cumulative number of deaths"),
    xaxis = list(title = "Date"),
    legend = list(x = 0.1, y = 0.9),
    hovermode = "compare"
  )
```

Comparison
=======================================================================


### **Daily new confirmed deaths - moving average**
    
```{r}

data1 <- data %>% 
    group_by(location) %>% 
    filter(iso_code == "DNK" | iso_code == "SWE" | iso_code == "NOR")

daily_deaths <- data1 %>%
    mutate(rollingmean = c(rep(NA, 3),  # Adding a rolling mean
                         zoo::rollmean(x = new_deaths, k = 7), 
                         rep(NA, 3))) %>%
  dplyr::filter(date >= "2020-03-01") %>%
  dplyr::mutate(country = location) %>%
  dplyr::group_by(date, country) %>%
  dplyr::summarise(total = sum(rollingmean)) %>%
  dplyr::ungroup() %>%
  tidyr::pivot_wider(names_from = country, values_from = total)


#----------------------------------------
# Plotting the data
daily_deaths %>%
  
  plotly::plot_ly() %>%
  plotly::add_trace(
    x = ~date,
    y = ~Denmark,
    type = "scatter",
    mode = "lines+markers",
    name = "Denmark"
  ) %>%
  plotly::add_trace(
    x = ~date,
    y = ~Sweden,
    type = "scatter", 
    mode = "lines+markers",
    name = "Sweden"
  ) %>%
  plotly::add_trace(
    x = ~date,
    y = ~Norway,
    type = "scatter",
    mode = "lines+markers",
    name = "Norway"
  ) %>%
  plotly::layout(
    title = "",
    legend = list(x = 0.1, y = 0.9),
    yaxis = list(title = "Number of new confirmed deaths"),
    xaxis = list(title = "Date"),
    # paper_bgcolor = "black",
    # plot_bgcolor = "black",
    # font = list(color = 'white'),
    hovermode = "compare",
    margin = list(
      # l = 60,
      # r = 40,
      b = 10,
      t = 10,
      pad = 2
    )
  )
```


R - values
=======================================================================

Column {data-width=400}
-------------------------------------

### **Denmark**
```{r}
knitr::opts_chunk$set(echo = FALSE) 
library(R0)
library(dplyr)
# set the serial interval to a lognormal distribution with a mean of 4.8 and a spread of 2.3
mGT <- generation.time("lognormal", c(4.7, 2.9)) 

#https://www.researchgate.net/publication/339705453_Serial_interval_of_novel_coronavirus_COVID-19_infections

    #url <- "https://api.covid19data.dk/ssi_newly_hospitalized"
    
    #hosp_raw <- jsonlite::fromJSON(url)
    #hosp <- hosp_raw
    #hosp_raw <- read_delim("Newly_admitted_over_time.csv", 
    #    ";", escape_double = FALSE, trim_ws = TRUE)

test_positive <- read_delim("Test_pos_over_time.csv", 
    ";", escape_double = FALSE, locale = locale(decimal_mark = ",", 
        grouping_mark = "."), trim_ws = TRUE)

test_positive$Date <- as.Date(test_positive$Date)

test_positive <- test_positive %>%
  filter(test_positive$Date > as.Date("2020-02-29"))


    #incidence <- hosp_raw$newly_hospitalized[10:length(hosp_raw$newly_hospitalized)]

    incidence <- test_positive$NewPositive[1:(length(test_positive$NewPositive)-3)]
    
    # incidence <- incidence[1:length(incidence)]
    begin <- as.integer(1)
    end <- as.integer(length(incidence))
   
    
    r <- est.R0.TD(incidence, GT = mGT, begin = begin, end = end,
                           date.first.obs = test_positive$Date[1])
     
    epid <- r$epid$t[1:length(r$conf.int$upper)]
    
    conf <- r$conf.int
    
    upper <- r$conf.int$upper
    
    lower <- r$conf.int$lower
    
    df_conf <- data.frame(epid, upper, lower, r$R)
    
    a <- list(
      text = "Based on new positive tests",
      xref = "paper",
      yref = "paper",
      yanchor = "bottom",
      xanchor = "left",
      align = "right",
      x = 0,
      y = 0,
      showarrow = FALSE
    )
    
    fig <- plot_ly(df_conf, x = ~epid, y = ~upper, type = 'scatter', mode = 'lines',
                   line = list(color = 'transparent'),
                   showlegend = FALSE, name = "confidence interval") 
    
    fig <- fig %>% add_trace(y = ~lower, type = 'scatter', mode = 'lines',
                            fill = 'tonexty', fillcolor = 'rgba(0,100,80,0.2)', line = list(color = 'transparent'),
                   showlegend = FALSE, name = "confidence interval") 
    
    fig <- fig %>% add_trace(x = ~epid, y = ~r$R, type = 'scatter', mode = 'lines',
                             line = list(color = 'rgb(0,100,80)'),
                             name = 'R value')
    
    fig <- fig %>% layout(title = "R values - Denmark - based on new postive tests", annotations = a,
                          paper_bgcolor = 'rgb(255,255,255)', plot_bgcolor = 'rgb(229,229,229)',
                          xaxis = list(title = "Date",
                                       gridcolor = 'rgb(255,255,255)',
                                       showgrid = TRUE,
                                       showline = FALSE,
                                       showticklabels = TRUE,
                                       tickcolor = 'rgb(127,127,127)',
                                       ticks = 'outside',
                                       zeroline = FALSE),
                          yaxis = list(title = "R value",
                                       gridcolor = 'rgb(255,255,255)',
                                       showgrid = TRUE,
                                       showline = FALSE,
                                       showticklabels = TRUE,
                                       tickcolor = 'rgb(127,127,127)',
                                       ticks = 'outside',
                                       range = c(0,4),
                                       zeroline = FALSE))
    
    fig

```

### **Sweden**
```{r}
knitr::opts_chunk$set(echo = FALSE)
url <- "https://www.arcgis.com/sharing/rest/content/items/b5e7488e117749c19881cce45db13f7e/data"

# Download Excel-file to temp file
xls_file <- tempfile()
utils::download.file(url, xls_file, mode = "wb")

# Read Excel-file and extract data from the sheet named "Antal intensivvårdade per dag"
# Sverige <- read_excel(
#  xls_file,
#  sheet = "Antal intensivvårdade per dag",
#  col_names = c("ICU_date","ICU"),
#  col_types = c("date","numeric"),
#  skip = 1)

Sverige <- read_excel(xls_file, sheet = "Antal per dag region")
# Antal avlidna per dag



mGT <- generation.time("lognormal", c(4.7, 2.9)) #https://www.researchgate.net/publication/339705453_Serial_interval_of_novel_coronavirus_COVID-19_infections

incidenceS <- Sverige$Totalt_antal_fall
#incidenceS <- ICU$ICU
endS <- as.integer(length(incidenceS) - 8)
beginS <- as.integer(1)

rs <- est.R0.TD(incidenceS, GT = mGT, begin = beginS, end = endS,
                       date.first.obs = first(Sverige$Statistikdatum))
      
epidS <- rs$epid$t[1:(length(incidenceS) - 8)]

confS <- rs$conf.int

upperS <- rs$conf.int$upper

lowerS <- rs$conf.int$lower

df_confS <- data.frame(epidS, upperS, lowerS, rs$R)

a <- list(
  text = "Based on new positive tests",
  xref = "paper",
  yref = "paper",
  yanchor = "bottom",
  xanchor = "left",
  align = "right",
  x = 0,
  y = 0,
  showarrow = FALSE
)

fig <- plot_ly(df_confS, x = ~epidS, y = ~upperS, type = 'scatter', mode = 'lines',
               line = list(color = 'transparent'),
               showlegend = FALSE, name = "confidence interval") 

fig <-fig %>% add_trace(y = ~lowerS, type = 'scatter', mode = 'lines',
                        fill = 'tonexty', fillcolor='rgba(0,100,80,0.2)', line = list(color = 'transparent'),
               showlegend = FALSE, name = "confidence interval") 

fig <- fig %>% add_trace(x = ~epidS, y = ~rs$R, type = 'scatter', mode = 'lines',
                         line = list(color='rgb(0,100,80)'),
                         name = 'R value')

fig <- fig %>% layout(title = "R values - Sweden - based on new postive tests", annotations = a,
                      paper_bgcolor='rgb(255,255,255)', plot_bgcolor='rgb(229,229,229)',
                      xaxis = list(title = "Date",
                                   gridcolor = 'rgb(255,255,255)',
                                   showgrid = TRUE,
                                   showline = FALSE,
                                   showticklabels = TRUE,
                                   tickcolor = 'rgb(127,127,127)',
                                   ticks = 'outside',
                                   zeroline = FALSE),
                      yaxis = list(title = "R value",
                                   gridcolor = 'rgb(255,255,255)',
                                   showgrid = TRUE,
                                   showline = FALSE,
                                   showticklabels = TRUE,
                                   tickcolor = 'rgb(127,127,127)',
                                   ticks = 'outside',
                                   range = c(0,4),
                                   zeroline = FALSE))

fig

```

Development
=======================================================================

Column {data-width=400}
-------------------------------------

### **Denmark - new positive**
```{r}
library(tidyverse)
#url <- "https://api.covid19data.dk/ssi_newly_hospitalized"

#hosp_raw <- jsonlite::fromJSON(url)

#hosp_raw <- hosp_raw %>%
# as_tibble() %>%
# mutate(date = date %>% lubridate::ymd_hms() %>% as.Date())

## Do data transformations #####################################################

# The last four days are usually not fully up-to-date and are missing 
# hospitalizations. So we will cut the last four entries and create a 7-day 
# rolling mean

#ads <- hosp_raw %>%
#  slice(1:(n()-4)) %>% # remove last four entries
#  mutate(rollingmean = c(rep(NA, 3),  # Adding a rolling mean
#                         zoo::rollmean(x = newly_hospitalized, k = 7), 
#                         rep(NA, 3)))

# ads %>% 
#  ggplot() + 
#  geom_bar(aes(date, newly_hospitalized), stat = "identity", fill = "Purple") + 
#  geom_line(aes(date, rollingmean)) +
#  theme_minimal()
  
  plotfit(r)

```

### **Sweden - new positive**
```{r}
  plotfit(rs)
```



About
=======================================================================

**The Coronavirus Dashboard: the case of Denmark**

This [Coronavirus dashboard: the case of Denmark](https://www.antoinesoetewey.com/files/coronavirus-dashboard.html) provides an overview of the 2019 Novel Coronavirus COVID-19 (2019-nCoV) epidemic for Denmark. This dashboard is built with R using the R Makrdown framework and was adapted from this [dashboard](https://ramikrispin.github.io/coronavirus_dashboard/){target="_blank"} by Rami Krispin.

**Code**

The code behind this dashboard is available on [GitHub](https://github.com/AntoineSoetewey/coronavirus_dashboard){target="_blank"}.

**Data**

The data and dashboard are refreshed on a daily basis.

The raw data is pulled from the ECDC read.csv("https://opendata.ecdc.europa.eu/covid19/casedistribution/csv", na.strings = "", fileEncoding = "UTF-8-BOM").

**Information**

More information about this dashboard (and how to replicate it for your own country) can be found in this [article](https://www.statsandr.com/blog/how-to-create-a-simple-coronavirus-dashboard-specific-to-your-country-in-r/).

**Update**

The data is as of `r format(max(data$date), "%A %B %d, %Y")` and the dashboard has been updated on `r format(Sys.time(), "%A %B %d, %Y")`.



*Go back to [www.statsandr.com](https://www.statsandr.com/) (blog) or [www.antoinesoetewey.com](https://www.antoinesoetewey.com/) (personal website)*.