Summary

Row

confirmed

2,551

Recovered

1,070

death

40 (1.6%)

Row

Column

Daily cumulative cases by type

7 day moving average

Comparison

Column

Daily new confirmed cases

Cases distribution by type

Map

Map of Eswatini (No information is available for regional distribution of cases)

About

The Coronavirus Dashboard: the case of Eswatini

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

Data

The input data for this dashboard is the dataset available from the {coronavirus} R package. Make sure to download the development version of the package to have the latest data (and add the function update_dataset() after loading the library for future updates):

install.packages("devtools")
devtools::install_github("RamiKrispin/coronavirus")

The data and dashboard are refreshed on a daily basis.

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

Update

The data is as of Wednesday July 29, 2020 and the dashboard has been updated on Thursday July 30, 2020.

---
title: "Coronavirus in Eswatini"
author: "Ermias Amene"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    #social: menu
    theme: cerulean #flatly #cerulean #cosmo #sandstone #united sandstone #yeti #bootstrap #cosmo
    # social: ["facebook", "twitter", "linkedin"]
    source_code: embed
    vertical_layout: fill
---






```{r setup, include=FALSE}
#------------------ Packages ------------------
# install.packages("devtools")
# devtools::install_github("RamiKrispin/coronavirus", force = TRUE)
library(coronavirus)

# max(coronavirus$date)

Inst_Load_Pkg <- function(pkg){
  new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
  if (length(new.pkg))
    install.packages(new.pkg, dependencies = TRUE)
  sapply(pkg, require, character.only = TRUE)
}

# usage
packages <- c("ggplot2",  "dplyr", "rmarkdown", "shiny", "tidyverse", 
             "plyr", "dplyr", "knitr", "sjlabelled",  "htmltools","plotly" ,
              "kableExtra","flexdashboard","leaflet","leafpop","purrr")
Inst_Load_Pkg(packages)

library(coronavirus)

#update_dataset()

data(coronavirus)

# A function for calculating 7 day moving average 
mav <- function(x, n=20){stats::filter(x,rep(1/n,n), sides=2)}

`%>%` <- magrittr::`%>%`
#------------------ Parameters ------------------
# Set colors
# https://www.w3.org/TR/css-color-3/#svg-color
confirmed_color <- "#4169E1"
active_color <- "#4169E1"
recovered_color <-  "#DAA520"
death_color <- "#800000"
#------------------ Data ------------------
df <- coronavirus %>%
  # dplyr::filter(date == max(date)) %>%
  dplyr::filter(country == "Eswatini") %>%
  dplyr::group_by(country, type) %>%
  dplyr::summarise(total = sum(cases)) %>%
  tidyr::pivot_wider(
    names_from = type,
    values_from = total
  ) %>%
   dplyr::mutate(unrecovered = confirmed - ifelse(is.na(recovered), 0, recovered) - ifelse(is.na(death), 0, death)) %>%
  #dplyr::mutate(unrecovered = confirmed - ifelse(is.na(death), 0, death)) %>%
  dplyr::arrange(-confirmed) %>%
  dplyr::ungroup() %>%
  dplyr::mutate(country = dplyr::if_else(country == "United Arab Emirates", "UAE", country)) %>%
  dplyr::mutate(country = dplyr::if_else(country == "Mainland China", "China", country)) %>%
  dplyr::mutate(country = dplyr::if_else(country == "North Macedonia", "N.Macedonia", country)) %>%
  dplyr::mutate(country = trimws(country)) %>%
  dplyr::mutate(country = factor(country, levels = country))

df_daily <- coronavirus %>%
  dplyr::filter(country == "Eswatini") %>%
  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)
  )


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

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

Row {data-width=50}
-----------------------------------------------------------------------

### confirmed {.value-box}

```{r}

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

### Recovered {.value-box}

```{r}

valueBox(
  value = paste(format(sum(df$recovered), big.mark = ","), "", sep = " "),
  caption = "Total recovered cases",
  icon = "far fa-laugh",
  color = recovered_color
)
```

### death {.value-box}

```{r}

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


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

Column {data-width=4000}
-------------------------------------

### **Daily cumulative cases by type** 
    
```{r}
plotly::plot_ly(data = df_daily) %>%
  plotly::add_trace(
    x = ~date,
    # y = ~active_cum,
    y = ~confirmed_cum,
    type = "scatter",
    mode = "lines+markers",
    # name = "Active",
    name = "Confirmed",
    line = list(color = confirmed_color),
    marker = list(color = confirmed_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-03-14"),
    y = 1,
    text = paste("First case"),
    xref = "x",
    yref = "y",
    arrowhead = 5,
    arrowhead = 3,
    arrowsize = 1,
    showarrow = TRUE,
    ax = -50,
    ay = -140
  ) %>%
  plotly::add_annotations(
    x = as.Date("2020-04-16"),
    y = 1,
    text = paste("First death"),
    xref = "x",
    yref = "y",
    arrowhead = 5,
    arrowhead = 3,
    arrowsize = 1,
    showarrow = TRUE,
    ax = -5,
    ay = -110
  ) %>%
  plotly::add_annotations(
    x = as.Date("2020-03-17"),
    y = 30,
    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"
  )
```

### **7 day moving average**
    
```{r}

coronavirus$trace_ma <-mav(coronavirus$cases)

coronavirusF <- coronavirus %>%
  dplyr::filter(date >= "2020-02-29") %>%
  dplyr::filter(country == "Eswatini")%>%
  dplyr::filter(type == "confirmed")
plot_ly(coronavirusF, x = ~date, y = ~trace_ma, 
               name = '7 Day Moving Average',
               type = 'scatter', mode = 'lines',
               line = list(color = confirmed_color))%>%
  
    plotly::layout(
      yaxis = list(title = "Confirmed Cases"),
      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
    )
  )
```


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


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


### **Daily new confirmed cases**
    
```{r}
daily_confirmed <- coronavirus %>%
  dplyr::filter(type == "confirmed") %>%
  dplyr::filter(date >= "2020-02-29") %>%
  dplyr::mutate(country = country) %>%
  dplyr::group_by(date, country) %>%
  dplyr::summarise(total = sum(cases)) %>%
  dplyr::ungroup() %>%
  tidyr::pivot_wider(names_from = country, values_from = total)

#----------------------------------------
# Plotting the data
#trace_ma <-mav(coronavirus$cases)

daily_confirmed %>%
  plotly::plot_ly() %>%
  plotly::add_trace(
    x = ~date,
    y = ~Eswatini,
    type = "scatter",
    mode = "lines+markers",
    name = "Eswatini"
  ) %>%
  # plotly::add_trace(
  #   x = ~date,
  #   y = ~Kenya,
  #   type = "scatter",
  #   mode = "lines+markers",
  #   name = "Kenya"
  # ) %>%
  # plotly::add_trace(
  #   x = ~date,
  #   y = ~Moldova,
  #   type = "scatter",
  #   mode = "lines+markers",
  #   name = "Moldova"
  # ) %>%


  plotly::add_trace(
    x = ~date,
    y = ~Lesotho,
    type = "scatter",
    mode = "lines+markers",
    name = "Lesotho"
  ) %>%
  plotly::add_trace(
    x = ~date,
    y = ~Moldova,
    type = "scatter",
    mode = "lines+markers",
    name = "Moldova"
  ) %>%
  plotly::add_trace(
    x = ~date,
    y = ~Kenya,
    type = "scatter",
    mode = "lines+markers",
    name = "Kenya"
  ) %>%
  plotly::layout(
    title = "",
    legend = list(x = 0.1, y = 0.9),
    yaxis = list(title = "New confirmed cases"),
    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
    )
  )
```



### **Cases distribution by type**

```{r daily_summary}
df_EA <- coronavirus %>%
  # dplyr::filter(date == max(date)) %>%
  dplyr::filter(country == "Eswatini" |
                  country == "Lesotho" |
                   country == "Moldova" |
                   country == "Kenya") %>%
  dplyr::group_by(country, type) %>%
  dplyr::summarise(total = sum(cases)) %>%
  tidyr::pivot_wider(
    names_from = type,
    values_from = total
  ) %>%
   dplyr::mutate(unrecovered = confirmed - ifelse(is.na(recovered), 0, recovered) - ifelse(is.na(death), 0, death)) %>%
  #dplyr::mutate(unrecovered = confirmed - ifelse(is.na(death), 0, death)) %>%
  dplyr::arrange(confirmed) %>%
  dplyr::ungroup() %>%
  dplyr::mutate(country = dplyr::if_else(country == "United Arab Emirates", "UAE", country)) %>%
  dplyr::mutate(country = dplyr::if_else(country == "Mainland China", "China", country)) %>%
  dplyr::mutate(country = dplyr::if_else(country == "North Macedonia", "N.Macedonia", country)) %>%
  dplyr::mutate(country = trimws(country)) %>%
  dplyr::mutate(country = factor(country, levels = country))

plotly::plot_ly(
  data = df_EA,
  x = ~country,
  # y = ~unrecovered,
  y = ~ confirmed,
  # text =  ~ confirmed,
  # textposition = 'auto',
  type = "bar",
  name = "Confirmed",
  marker = list(color = active_color)
) %>%
  plotly::add_trace(
    y = ~death,
    # text =  ~ death,
    # textposition = 'auto',
    name = "Death",
    marker = list(color = death_color)
  ) %>%
  plotly::add_trace(
    y = ~recovered,
    # text =  ~ death,
    # textposition = 'auto',
    name = "Recovered",
    marker = list(color = '#6B8E23')
  ) %>%
  
  plotly::layout(
    barmode = "stack",
    yaxis = list(title = "Total cases"),
    xaxis = list(title = ""),
    hovermode = "compare",
    margin = list(
      # l = 60,
      # r = 40,
      b = 10,
      t = 10,
      pad = 2
    )
  )
```



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

### **Map of Eswatini** (*No information is available for regional distribution of cases*)

```{r}

cv_data_for_plot <- coronavirus %>%
  # dplyr::filter(country == "Eswatini") %>%
  dplyr::filter(cases > 0) %>%
  dplyr::group_by(country, province, lat, long, type) %>%
  dplyr::summarise(cases = sum(cases)) %>%
  dplyr::mutate(log_cases = 2 * log(cases)) %>%
  dplyr::ungroup()
cv_data_for_plot.split <- cv_data_for_plot %>% split(cv_data_for_plot$type)
pal <- colorFactor(c("orange", "red", "green"), domain = c("confirmed", "death", "recovered"))
map_object <- leaflet() %>% addProviderTiles(providers$Esri.NatGeoWorldMap)
names(cv_data_for_plot.split) %>%
  purrr::walk(function(df) {
    map_object <<- map_object %>%
      addCircleMarkers(
        data = cv_data_for_plot.split[[df]],
        lng = ~long, lat = ~lat,
        #                 label=~as.character(cases),
        color = ~ pal(type),
        stroke = FALSE,
        fillOpacity = 0.8,
        radius = ~log_cases,
        popup = leafpop::popupTable(cv_data_for_plot.split[[df]],
          feature.id = FALSE,
          row.numbers = FALSE,
          zcol = c("type", "cases", "country", "province")
        ),
        group = df,
        #                 clusterOptions = markerClusterOptions(removeOutsideVisibleBounds = F),
        labelOptions = labelOptions(
          noHide = F,
          direction = "auto"
        )
      )%>%
      setView(lng=31.4659, lat=-26.5225, zoom = 7)
  })

map_object %>%
  addLayersControl(
    overlayGroups = names(cv_data_for_plot.split),
    options = layersControlOptions(collapsed = FALSE)
  )
```





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

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

This [Eswatini Coronavirus Dashboard](https://rpubs.com/ErmiasA/644480) provides an overview of the 2019 Novel Coronavirus COVID-19 (2019-nCoV) epidemic for Eswatini. 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 and modified for Eswatini by Ermias Amene (ermiaswm@gmail.com).


**Data**

The input data for this dashboard is the dataset available from the [`{coronavirus}`](https://github.com/RamiKrispin/coronavirus){target="_blank"} R package. Make sure to download the development version of the package to have the latest data (and add the function `update_dataset()` after loading the library for future updates):

```
install.packages("devtools")
devtools::install_github("RamiKrispin/coronavirus")
```

The data and dashboard are refreshed on a daily basis.

The raw data is pulled from the Johns Hopkins University Center for Systems Science and Engineering (JHU CCSE) Coronavirus [repository](https://github.com/RamiKrispin/coronavirus-csv){target="_blank"}.


**Update**

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