Column

Positive Covid-19 cases in counties in 19.01.2022

Source data: https://www.terviseamet.ee/et/koroonaviirus/avaandmed


Vaccination level in municipalities, 19.01.2022

Column

COVID-19 infections in counties in last 14 days


Hospitalization since the beginning of pandemic

---
title: "COVID-19 DASHBOARD"
author: TL
output: 
  flexdashboard::flex_dashboard:
    theme: yeti
    orientation: columns
    vertical_layout: fill
    source_code: embed
---

```{r setup, include=FALSE}
library(flexdashboard)
library(tidyverse)
library(ggthemes) 
library(plotly)
library(sf)
library(leaflet)
library(gganimate)
library(tmap)
library(dygraphs)
library(leaflet)
library(RColorBrewer)
library(curl)
library(tibbletime)
library(dygraphs)
```
Column
-----------------------------------------------------------------------
### Positive Covid-19 cases in counties in 19.01.2022 
Source data: https://www.terviseamet.ee/et/koroonaviirus/avaandmed

```{r}
covid19_test_county_all <- read.csv('opendata_covid19_test_county_all.csv', encoding = "UTF-8",  header=T, na.strings=c("","NA"))

covid19_test_county_all<- covid19_test_county_all %>%
  mutate(X.U.FEFF.LastStatisticsDate =as.Date(as.character(X.U.FEFF.LastStatisticsDate)), 
                  StatisticsDate=as.Date(as.character(StatisticsDate)))
covid19_test_county_all<- covid19_test_county_all %>% mutate (CountyEHAK = paste0("00", CountyEHAK))

covid19_test_county_all <- covid19_test_county_all %>%
  select('StatisticsDate',
         'County',
         'CountyEHAK',
         'ResultValue',
         'DailyCases')

covid19_test_county_all <- covid19_test_county_all %>%
  filter(ResultValue=='P')

covid19_test_county_all <- covid19_test_county_all%>%
  filter(!is.na(County))

county <- st_read('maakond_shp/maakond_20220101.shp', quiet=T)

county <- county %>% 
  st_simplify(preserveTopology = TRUE, dTolerance = 200) %>% 
  st_cast("MULTIPOLYGON")

covid19_test_county_all_viim <- covid19_test_county_all %>%
  select(CountyEHAK, DailyCases, StatisticsDate) %>%
  filter(StatisticsDate== max(StatisticsDate))

covid19_test_county_all_viim_sf <- left_join(county, covid19_test_county_all_viim, by = c("MKOOD" = "CountyEHAK"))

covid19_test_county_all_viim_sf_cntr <- covid19_test_county_all_viim_sf %>% 
  st_centroid()

covid19_test_county_all_viim_sf_4326 <- covid19_test_county_all_viim_sf %>% 
  st_transform(4326)
covid19_test_county_all_viim_sf_cntr4326 <- covid19_test_county_all_viim_sf %>% 
  st_transform(4326)

tmap_mode("view")

map1 <- tm_shape(covid19_test_county_all_viim_sf_4326)+
        tm_polygons(col = "DailyCases", 
              style = "quantile",
              palette = "seq",
              alpha = .7,
              title = "Positive cases")+
        tm_shape(covid19_test_county_all_viim_sf_cntr4326)+
            tm_text(text = "DailyCases",
          bg.color = "grey",
          shadow = T)

map1 + tm_view(set.view = c(25.0136, 58.5953, 6))

```

-----------------------------------------------------------------------

### Vaccination level in municipalities, 19.01.2022 

```{r}
vacc <- read.csv('opendata_covid19_vaccination_location_commune_agegroup_gender.csv', encoding = "UTF-8",  header=T, na.strings=c("","NA"))

vacc2 <- vacc%>%
   filter(!is.na(LocationCommuneEHAK))

vacc4 <- vacc2 %>%
  select('X.U.FEFF.StatisticsDate',
          'LocationCommuneEHAK',
         'LocationCommune',
         'LocationPopulation',
         'MeasurementType',
         'TotalCount')

vacc4<- vacc4 %>%
  mutate(X.U.FEFF.StatisticsDate =as.Date(as.character(X.U.FEFF.StatisticsDate)),
         LocationCommuneEHAK = paste0("0", LocationCommuneEHAK))
              
vacc5 <- vacc4%>%
  filter(X.U.FEFF.StatisticsDate == max(X.U.FEFF.StatisticsDate))

vacc5 <- vacc5%>%
  filter(MeasurementType == 'FullyVaccinated')

vacc5 <- vacc5%>%
  filter(!is.na(LocationPopulation))

vacc6 <- vacc5 %>% 
  group_by(LocationCommuneEHAK, LocationCommune) %>% 
  summarise(kokkuvaks = sum(TotalCount), elanikke=sum(LocationPopulation))%>%
  ungroup()
vacc7 <- vacc6
vacc7$Percent <- vacc6$kokkuvaks / vacc6$elanikke
vacc7$Percent <- vacc7$Percent*100

vacc7$Percent <- round(vacc7$Percent, digit = 1) 
vaccf <- vacc7%>%
  mutate(Percent = paste0("0", LocationCommuneEHAK))
  
municip <- st_read('omavalitsus_shp/omavalitsus_20211101.shp', quiet=T)
         
municip <- municip %>% 
  st_simplify(preserveTopology = TRUE, dTolerance = 200) %>% 
  st_cast("MULTIPOLYGON")

vacc_kaart<- left_join(municip, vacc7, by = c("OKOOD" = "LocationCommuneEHAK"))

vacc_kaart_cntr <- vacc_kaart %>% 
  st_centroid()

vacc_kaart_4326 <- vacc_kaart%>%
  st_transform(4326)
vacc_kaart_cntr_4326 <- vacc_kaart_cntr%>%
  st_transform(4326)

tmap_mode("view")

map2 <- tm_shape(vacc_kaart_4326)+
        tm_polygons(col = "Percent", 
              style = "quantile",
              palette = c("red", "yellow","darkgreen" ),
              alpha = .6,
              title = "Vaccination %")+
        tm_shape(vacc_kaart_cntr_4326)+
        tm_text(text = "Percent",
          size = 1,
          bg.color = "grey",
          shadow = T)

map2 + tm_view(set.view = c(25.0136, 58.5953, 6))
```
Column
-----------------------------------------------------------------------

### COVID-19 infections in counties in last 14 days

```{r}
covid19_test_county_chart <- read.csv('opendata_covid19_test_county_all.csv', encoding = "UTF-8",  header=T, na.strings=c("","NA"))

covid19_test_county_chart<- covid19_test_county_chart %>%
  mutate(X.U.FEFF.LastStatisticsDate =as.Date(as.character(X.U.FEFF.LastStatisticsDate)), 
                  StatisticsDate=as.Date(as.character(StatisticsDate)))
 
covid19_test_county_chart <- covid19_test_county_chart %>%
  select('StatisticsDate',
         'County',
         'CountyEHAK',
         'ResultValue',
         'DailyCases')
covid19_test_county_chart <- covid19_test_county_chart %>%
  filter(ResultValue=='P')

covid19_test_county_chart <- covid19_test_county_chart%>%
  filter(!is.na(County))

covid19_test_county_chart_t <- as_tbl_time(covid19_test_county_chart, index = StatisticsDate)

covid19_test_county_chart_valim <- covid19_test_county_chart %>%
  filter( StatisticsDate >= as.Date("2022-01-05"), StatisticsDate <= as.Date("2022-01-19"))

covid_cases <- ggplot(data=covid19_test_county_chart_valim, aes(x=StatisticsDate, y=DailyCases)) +
  geom_bar(stat="identity", fill="steelblue")+
  theme_minimal()+
  facet_wrap(vars(County), scale = "free_y")

plotly::ggplotly(covid_cases)
```

----------------------------------------------------------------------

###  Hospitalization since the beginning of pandemic

```{r}
hospital <- read.csv('opendata_covid19_hospitalization_timeline.csv', encoding = "UTF-8",  header=T, na.strings=c("","NA"))

hospital <- hospital %>%
  select('StatisticsDate',
         'Hospitalised',
         'IsOnVentilation',
         'IsInIntensive')

p = "Haiglas"
v = "Intensiivis"

hospital$Haiglas <- p
hospital$intensiivis <- v

hospital<- hospital %>%
  mutate(StatisticsDate=as.Date(as.character(StatisticsDate)))

hospital1 <- hospital %>% 
  pivot_wider(names_from = Haiglas, values_from = Hospitalised, id_cols = StatisticsDate)
hospital3 <- hospital %>% 
  pivot_wider(names_from = intensiivis, values_from = IsInIntensive, id_cols = StatisticsDate)

hospital_2 <- xts::xts(hospital1, order.by = hospital1$StatisticsDate) 
hospital_4 <- xts::xts(hospital3, order.by = hospital3$StatisticsDate) 

hospital_2$StatisticsDate <- NULL
hospital_4$StatisticsDate <- NULL

skeem <- cbind(hospital_2, hospital_4)
dygraph(skeem) %>%
  dySeries() %>% 
  dyRangeSelector()

```