World Situation

Row

14 Day Incidence

Covid 19

Covid 19 Infection worldwide

89'802'096

Covid 19 Deaths worldwide

1'940'529

Covid 19 Infection CH

482'094

Covid 19 Deaths CH

7'655

Covid 19 Infection last Week CH

22'434

Covid 19 Deaths last Week CH

417

Row

Chart A

Chart B

Chart C

Row

Chart D

Chart E

Chart F

Confirmend Cases / Deaths

Diverse Diagramme

Map

Switzerland Situation

Schweiz

Kantone

About Reports

Created by Hans U Deck Jan 2021

This dashboard was developed with R-Programming Language and with R Markdown.

---
title: "Dashboard Covid19"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: fill
    social: ["twitter", "facebook", "menu"]
    source_code: embed
---

```{r setup, include=FALSE}
library(flexdashboard)
library(ggplot2)
library(dplyr)
library(plyr)
library(DT)
library(data.table)
library(knitr)
library(rpivotTable)
library(plotly)
library(openintro)
library(highcharter)
library(ggvis)
library(covid19swiss)
library(tidyverse)
library(tidycovid19)
library(tidyverse)
library(zoo)


```


```{r}
data <- read.csv("https://opendata.ecdc.europa.eu/covid19/casedistribution/csv", na.strings = "")
dt <- data.table(data)


dt$countriesAndTerritories <- as.factor(dt$countriesAndTerritories)
dt$continentExp <- as.factor(dt$continentExp)
dt$countryterritoryCode <- as.factor(dt$countryterritoryCode)

# Change the Colum name
setnames(dt, "dateRep", "date")
setnames(dt, "notification_rate_per_100000_population_14.days", "days_14_10000")

# Convert to date
dt$date <- as.Date(dt$date, format = "%d/%m/%Y")

# Sort date acending
dt <- dt[order(date)]

dt.world.sum_cases <- dt[, .(cases_weekly_sum = sum(cases_weekly)), by = dt$date]
dt.world.sum_deaths <- dt[, .(deaths_weekly_sum = sum(deaths_weekly)), by = dt$date]
dt.world.sum <- cbind(dt.world.sum_cases, dt.world.sum_deaths)
dt.world.sum <- dt.world.sum[, !3]


ch <- filter(dt, countryterritoryCode == "CHE")
sw <- filter(dt, countryterritoryCode == "SWE")
fin <- filter(dt,countryterritoryCode == "FIN")
irl <- filter(dt,countryterritoryCode == "IRL")
gbr <- filter(dt,countryterritoryCode == "GBR")
```

World Situation
======================================


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

### 14 Day Incidence

```{r}
valueBox(paste("Covid 19 "), last(dt$date),
         color = "warning")
```


### Covid 19 Infection worldwide

```{r}



x1 <-format( sum(data$cases_weekly)  , decimal.mark=",", big.mark="'")
valueBox(x1)
      


```



### Covid 19 Deaths worldwide

```{r}
x1 <-format( sum(data$deaths_weekly)  , decimal.mark=",", big.mark="'")
valueBox(x1, color = "red")




```


### Covid 19 Infection CH

```{r}


x1 <-format( sum(ch$cases_weekly)  , decimal.mark=",", big.mark="'")
valueBox(x1)

```


### Covid 19 Deaths CH

```{r}

x1 <-format( sum(ch$deaths_weekly)  , decimal.mark=",", big.mark="'")
valueBox(x1)
```


### Covid 19 Infection last Week CH

```{r}
#valueBox(last(ch$cases_weekly))

x1 <-format( last(ch$cases_weekly)  , decimal.mark=",", big.mark="'")
valueBox(x1)

```


### Covid 19 Deaths last Week CH

```{r}
#valueBox(last(ch$deaths_weekly),
#         color = "red")
x1 <-format( last(ch$deaths_weekly)  , decimal.mark=",", big.mark="'")
valueBox(x1 , color = "red")

```


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

### Chart A

```{r}
p <- ggplot(dt.world.sum, mapping = aes(x = dt, y = cases_weekly_sum)) +
  geom_area( fill = "lightblue") +
   ggtitle("Covid 19 Cases Worldwide") + 
  xlab("Date") + 
  ylab("14 Day Incidence") +
  theme_minimal()

fig <- ggplotly(p)
fig


```


### Chart B

```{r}
p <- ggplot(dt.world.sum, mapping = aes(x = dt, y = deaths_weekly_sum)) +
  geom_area( fill = "lightblue") +
   ggtitle("Covid 19 Deaths Worldwide") + 
  xlab("Date") + 
  ylab("14 Day Deaths") +
  theme_minimal()

fig <- ggplotly(p)
fig

```


### Chart C

```{r}
df.ecdc <- read.csv("https://opendata.ecdc.europa.eu/covid19/casedistribution/csv", na.strings = "")




# Definiton Factors
df.ecdc$countriesAndTerritories <- as.factor(df.ecdc$countriesAndTerritories)
df.ecdc$continentExp <- as.factor(df.ecdc$continentExp)

# Change the Colum name
setnames(df.ecdc, "dateRep", "date")

# Convert to date
df.ecdc$date <- as.Date(df.ecdc$date, format = "%d/%m/%Y")

# Sort date acending
df.ecdc <- data.table(df.ecdc)
df.ecdc <- df.ecdc[order(date)]

dt.europe <- df.ecdc[df.ecdc$continentExp == "Europe", ]
dt.europe.allcases <- dt.europe[, .(cases_weekly_sum = sum(cases_weekly)), by = dt.europe$date]
dt.europe.alldeaths <- dt.europe[, .(deaths_weekly_sum = sum(deaths_weekly)), by = dt.europe$date]
setnames(dt.europe.allcases, "cases_weekly_sum", "europe_cases_weekly")
setnames(dt.europe.alldeaths, "deaths_weekly_sum", "europe.deaths_weekly")


# Asia
dt.asia <- df.ecdc[df.ecdc$continentExp == "Asia", ]
dt.asia.allcases <- dt.asia[, .(cases_weekly_sum = sum(cases_weekly)), by = dt.asia$date]
dt.asis.alldeaths <- dt.asia[, .(deaths_weekly_sum = sum(deaths_weekly)), by = dt.asia$date]
setnames(dt.asia.allcases, "cases_weekly_sum", "asia_cases_weekly")
setnames(dt.asis.alldeaths, "deaths_weekly_sum", "asia.deaths_weekly")


# America
dt.america <- df.ecdc[df.ecdc$continentExp == "America", ]
dt.america.allcases <- dt.america[, .(cases_weekly_sum = sum(cases_weekly)), by = dt.america$date]
dt.america.alldeaths <- dt.america[, .(deaths_weekly_sum = sum(deaths_weekly)), by = dt.america$date]
setnames(dt.america.allcases, "cases_weekly_sum", "america_cases_weekly")
setnames(dt.america.alldeaths, "deaths_weekly_sum", "america_deaths_weekly")

# Africa
dt.africa <- df.ecdc[df.ecdc$continentExp == "Africa", ]
dt.africa.allcases <- dt.africa[, .(cases_weekly_sum = sum(cases_weekly)), by = dt.africa$date]
dt.africa.alldeaths <- dt.africa[, .(deaths_weekly_sum = sum(deaths_weekly)), by = dt.africa$date]
setnames(dt.africa.allcases, "cases_weekly_sum", "africa_cases_weekly")
setnames(dt.africa.alldeaths, "deaths_weekly_sum", "africa_deaths_weekly")

# Oceania
dt.oceania <- df.ecdc[df.ecdc$continentExp == "Oceania", ]
dt.oceania.allcases <- dt.oceania[, .(cases_weekly_sum = sum(cases_weekly)), by = dt.oceania$date]
dt.oceania.alldeaths <- dt.oceania[, .(deaths_weekly_sum = sum(deaths_weekly)), by = dt.oceania$date]
setnames(dt.oceania.allcases, "cases_weekly_sum", "oceania_cases_weekly")
setnames(dt.oceania.alldeaths, "deaths_weekly_sum", "oceania.deaths_weekly")


dt.continents <- cbind(dt.europe.allcases, dt.asia.allcases)
dt.continents <- dt.continents[, -3]
setnames (dt.continents, "dt.europe", "date")
dt.continents <- cbind(dt.continents, dt.america.allcases)
dt.continents <- dt.continents[, -4]
dt.continents <- cbind(dt.continents, dt.africa.allcases)
dt.continents <- dt.continents[, -5]
dt.continents <- cbind(dt.continents, dt.oceania.allcases)
dt.continents <- dt.continents[, -6]


x <- list(
  title = "Date"
)
y <- list(
  title = "Weekly Infections "
)

fig<- plot_ly(dt.continents, x = ~date, y = ~europe_cases_weekly, name= "Europe", type = "scatter", mode = "lines")
fig <- fig %>% add_trace(y = ~asia_cases_weekly, name = "Asia", type ="scatter", mode = "lines")
fig <- fig %>% add_trace(y = ~america_cases_weekly, name = "America", type ="scatter", mode = "lines")
fig <- fig %>% add_trace(y = ~africa_cases_weekly, name = "Africa", type ="scatter", mode = "lines")
fig <- fig %>% add_trace(y = ~oceania_cases_weekly, name = "Oceania", type ="scatter", mode = "lines")
fig <- fig %>% layout(
  title = "Weekly Infections in Continents",
  xaxis = x, yaxis = y
)

fig
```


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

### Chart D

```{r}
fig <- plot_ly(
  type = "scatter",
  x = ch$date,
  y = ch$cases_weekly,
  name = 'CHE',
  mode = "lines") 
fig <- fig %>%
  add_trace(
    type = "scatter",
    x = sw$date, 
    y = sw$cases_weekly,
    name = "SWE",
    mode = "lines")
     
fig <- fig %>%
  add_trace(
    type = "scatter",
    x = fin$date, 
    y = fin$cases_weekly,
    name = "FIN",
    mode = "lines",
    line = list(
      color = 'black'
    )) 

fig <- fig %>%
  add_trace(
    type = "scatter",
    x = irl$date, 
    y = irl$cases_weekly,
    name = "IRL",
    mode = "lines",
    line = list(
      color = 'black'
    )) 



fig



```


### Chart E

```{r}
fig <- plot_ly(
  type = "scatter",
  x = ch$date,
  y = ch$deaths_weekly,
  name = 'CHE',
  mode = "lines") 
fig <- fig %>%
  add_trace(
    type = "scatter",
    x = sw$date, 
    y = sw$deaths_weekly,
    name = "SWE",
    mode = "lines")
     
fig <- fig %>%
  add_trace(
    type = "scatter",
    x = fin$date, 
    y = fin$deaths_weekly,
    name = "FIN",
    mode = "lines",
    line = list(
      color = 'black'
    )) 

fig <- fig %>%
  add_trace(
    type = "scatter",
    x = irl$date, 
    y = irl$deaths_weekly,
    name = "IRL",
    mode = "lines",
    line = list(
      color = 'black'
    )) 



fig

```

### Chart F

```{r}

merged <- download_merged_data(cached = TRUE, silent = TRUE)

ch_merged <- filter(merged, iso3c == "CHE")
#coeff <- 100000

#p <-ggplot(ch_merged, aes(x=date)) +
  
 # geom_line( aes(y=total_tests - lag(total_tests))) + 
 # geom_line( aes(y=positive_rate * coeff), size = 0.8, color ="red") + # Divide by 10 to get the same range than the #temperature
  
 # scale_y_continuous(
    
    # Features of the first axis
  #  name = "Total Tests per Day",
    
    # Add a second axis and specify its features
 #   sec.axis = sec_axis(~./coeff, name="Positive Rate")
 # ) +
 # theme_minimal()

#plot(p)

fig <- plot_ly(ch_merged, x = ~date, y = ~ total_tests - lag(total_tests), type = "scatter", mode = "lines", name = "Daily Test") %>%
  add_trace(x = ~date, y = ~positive_rate, mode = "lines", yaxis = "y2", name = "Positiv Rate") %>%
  layout(yaxis2 = list(overlaying = "y", side = "right"))

fig
```



Confirmend Cases / Deaths
========================================================================

```{r}

df <- download_merged_data(cached = TRUE, silent = TRUE)

countries <- c(
  "CHE", "SWE", "NER", "DEU", "GBR", "ITA", "AUT", "NZL", "AUS", "IRL", "BEL",
  "FRA", "LTU", "DNK", "BRA", "IND", "LUX", "ESP", "NLD", "NOR", "CAN", "CHN", "FIN"
)
l_countries <- length(countries)

test.confirmed <- aggregate(df$confirmed, by=list(df$iso3c), FUN= max)
test.soc_dist  <- aggregate(df$soc_dist, by=list(df$iso3c), FUN = max)
test.deaths    <- aggregate(df$deaths, by=list(df$iso3c), FUN = max)
test.pop       <- aggregate(df$population, by = list(df$iso3c), FUN = max)

#test <- cbind(test.confirmed, test.soc_dist)
test <- cbind(test.confirmed, test.deaths)
test <- cbind(test, test.pop)
test <- test[, -5]
test <- test[, -3]
setnames(test, "Group.1", "iso3c")
setnames(test, "x", "confirmend_cases")
setnames(test, "x.1", "deaths")
setnames(test, "x.2", "pop")

test.x <- filter(test, confirmend_cases >=1000)

df.x21 <- filter(test.x, iso3c == countries[1])

for (i in 2:l_countries) {
  df.x2 <- filter(test.x, iso3c == countries[i])
  df.x21 <- rbind(df.x21, df.x2)
 
}


p <- ggplot(df.x21, mapping = aes(x = (confirmend_cases / pop)*100000, y = (deaths/ pop)*100000)) +
  geom_point() +
  ggrepel::geom_label_repel(ggplot2::aes(label = iso3c), show.legend = TRUE) +
  ggplot2::scale_x_continuous(trans = "log10", labels = scales::comma) +
  ggplot2::scale_y_continuous(labels = scales::comma) +  
  theme_minimal() +
  labs(
    x = "Reported Confirmend Cases / 100'000 ",
    y = "Number of Deaths / 100'000"
  )
plot(p)



```



Diverse Diagramme
========================================================================

```{r}

plot_covid19_stripes(
        type = "confirmed",
        countries =  c("CHE", "ITA" ,"ESP", "GBR"),
        sort_countries = "countries"
)

```

Map
=======================================================================

```{r}

merged <- download_merged_data(silent = TRUE, cached = TRUE)
map_covid19(merged, type = "confirmed", region = "Europe")


```


Switzerland Situation
=========================================================================

### Schweiz

```{r}

```


### Kantone

```{r}
library(readr)
library(zoo)
#-------------- Functions-----
calc_cases_diff_7 <- function(can)  {

can <- covid19swiss_wide %>%
        filter(location == can) %>%
          mutate( cases_diff = cases_total - lag(cases_total)) %>%    #Prüfen oh cases_total 0 ist
          mutate(cases_7 =  round(rollmean(cases_diff, k = 7, fill = NA)))
          return (can)
}

#------------End Function


covid19_swiss <- refresh_covid19swiss()


#covid19_swiss[is.na(covid19_swiss)] <- 0

covid19swiss_wide <- covid19_swiss %>%
        pivot_wider(names_from = data_type, values_from = value)
#--------------------------------
pop_can <- read.delim("Bevölerung Ch Kantone reduziert.csv", sep = ";")
pop_can <- pop_can[,-2]
#-------------------------------------------------
can <- c("AG", "AI","AR","BE","BL","BS","FR","GE","GL","GR","JU", "LU","NE","NW",
         "OW","SG","SH","SO","SZ","TG","TI","UR","VD","VS","ZG","ZH")

#can <- c("AI", "ZH", "VD", "ZG", "VS")
#can <- c("GE", "AG")

l <- length(can)
x.df.canton <- calc_cases_diff_7("AG")

for (i in 1:l) {


  x.df <- calc_cases_diff_7(can[i])
  
 
  x.df.canton <- bind_rows(x.df.canton, x.df)
}
p <- ggplot(x.df.canton, aes(x = date, y = cases_7, color = location )) +
        geom_line(group = 2, size = 0.4) +
        theme_minimal()

fig <- ggplotly(p)
fig
```





About Reports
====================================================================================

Created by Hans U Deck 
Jan 2021

This dashboard was developed with R-Programming Language
and with R Markdown.