Summary

Row

confirmed

28

active

28 (100%)

recovered

0 (0%)

death

0 (0%)

Row

Cases Distribution by Type (Kenya)

Daily cumulative cases by type (Kenya)

Comparison

Column

Daily new cases (East African Countries)

World Map

World map of cases (use + and - icons to zoom in/out)

About

The Coronavirus Dashboard: the case of Kenya

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

Code: GitHub.

Data: {coronavirus} R package. Make sure to download the development version of the package to have the latest data:

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.

Reach out for any comments or feedback.

Update

The data is as of Wednesday March 25, 2020 and the dashboard has been updated on Friday March 27, 2020.

---
title: "Corona virus in Kenya"
author: "Carlvin.M."
output: 
  flexdashboard::flex_dashboard:
    theme: cosmo
    orientation: rows
    # social: ["facebook", "twitter", "linkedin"]
    source_code: embed
    vertical_layout: fill
---

```{r setup, include=FALSE}
#------------------ Packages ------------------
library(flexdashboard)
#checks if there is data update on the Github version
coronavirus::update_datasets(silence = TRUE)

library(coronavirus)
data(coronavirus)


`%>%` <- 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 ------------------
 coronavirus <- dplyr::add_row(coronavirus, Province.State = "Nairobi", Country.Region = "Kenya", Lat   = -0.0236, Long = 37.9062,date = "2020-03-12", cases = 0, type = "recovered")
 df <-  coronavirus %>%
  # dplyr::filter(date == max(date)) %>%
  dplyr::filter(Country.Region == "Kenya") %>%
  dplyr::group_by(Country.Region, 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.Region == "United Arab Emirates", "UAE", Country.Region)) %>%
  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.Region == "Kenya") %>%
  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(confirmed_cum = cumsum(confirmed),
                death_cum = cumsum(death),
                recovered_cum = cumsum(recovered)) %>%
  dplyr::mutate(active = (ifelse(is.na(confirmed), 0, confirmed) 
                - ifelse(is.na(death), 0, death) -  ifelse(is.na(recovered), 0, recovered)),
                active_cum = cumsum(active)) 


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

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

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

### confirmed {.value-box}

```{r}

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




### active {.value-box}

```{r}
valueBox(value = paste(format(sum(df$unrecovered, na.rm = TRUE), big.mark = ","), " (",
                       round(100 * sum(df$unrecovered, na.rm = TRUE) / sum(df$confirmed), 1), 
                       "%)", sep = ""), 
         caption = "Active Cases", icon = "fas fa-ambulance", 
         color = active_color)
```



### recovered {.value-box}

```{r}
valueBox(value = paste(format(sum(df$recovered, na.rm = TRUE), big.mark = ","), " (",
                       round(100 * sum(df$recovered, na.rm = TRUE) / sum(df$confirmed), 1), 
                       "%)", sep = ""), 
         caption = "Recovered Cases", icon = "fas fa-heartbeat", 
         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 = "Death cases (death rate)",
  icon = "fas fa-heart-broken",
  color = death_color
)
```


Row
-----------------------------------------------------------------------
### **Cases Distribution by Type (Kenya)**

```{r daily_summary}

cases <- as.numeric(df[1,3:5])
type <- names(df[3:5])

piedata <- as.data.frame(cbind(cases,type))
plotly::plot_ly(piedata, labels=~type, values=~cases, type ='pie',
                 textposition = 'inside',
        textinfo = 'label+percent',
        insidetextfont = list(color = '#FFFFFF'),
        hoverinfo = 'text',
        # marker = list(colors = colors,
        #               line = list(color = '#FFFFFF', width = 1)),
                      #The 'pull' attribute can also be used to create space between the sectors
        showlegend = F)

```


### **Daily cumulative cases by type (Kenya)** 

```{r}
plotly::plot_ly(data = df_daily %>% dplyr::filter(date >= "2020-03-12")) %>%
  plotly::add_trace(x = ~ date,
                    y = ~ active_cum,
                    type = "scatter",
                    mode = "lines+markers",
                    name = "Active",
                    line = list(color = active_color),
                    marker = list(color = active_color)) %>%
  plotly::add_trace(x = ~ date,
                    y = ~ recovered_cum,
                    type = "scatter",
                    mode = "lines+markers",
                    name = "Recovered",
                    line = list(color = recovered_color),
                    marker = list(color = recovered_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-13"),
    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-26"),
    y = 3,
    text = paste("First 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-18"),
  #   y = 14,
  #   text = paste(
  #     "New containment",
  #     "",
  #     "measures"
  #   ),
  #   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"
  )
```




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


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


### **Daily new cases (East African Countries)**
    
```{r}
daily_confirmed <- coronavirus %>%
  dplyr::filter(type == "confirmed") %>%
  dplyr::filter(date >= "2020-03-12") %>%
  dplyr::mutate(country = Country.Region) %>%
  dplyr::group_by(date, country) %>%
  dplyr::summarise(total = sum(cases)) %>%
  dplyr::ungroup() %>%
  tidyr::pivot_wider(names_from = country, values_from = total)

#----------------------------------------
# Plotting the data

daily_confirmed %>%
  plotly::plot_ly() %>%
  plotly::add_trace(
    x = ~date,
    y = ~Kenya,
    size = ~Kenya,
    type = "scatter",
    mode = "lines+markers",
    name = "Kenya"
  ) %>%
  plotly::add_trace(
    x = ~date,
    y = ~Uganda,
    size = ~Uganda,
    type = "scatter",
    #mode = "lines+markers",
    name = "Uganda"
  ) %>%
  plotly::add_trace(
    x = ~date,
    y = ~Ethiopia,
    size = ~Ethiopia,
    type = "scatter",
    #mode = "lines+markers",
    name = "Ethiopia"
  ) %>%
  plotly::add_trace(
    x = ~date,
    y = ~Tanzania,
    size = ~Tanzania,
    type = "scatter",
    #mode = "lines+markers",
    name = "Tanzania"
  ) %>%
  plotly::layout(
    title = "",
    legend = list(x = 0.1, y = 0.9),
    yaxis = list(title = "Number of new 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
    )
  )
```



























































World Map
=======================================================================

### **World map of cases** (*use + and - icons to zoom in/out*)

```{r}
# map tab added by Art Steinmetz
library(leaflet)
library(leafpop)
library(purrr)
cv_data_for_plot <- coronavirus %>%
  # dplyr::filter(Country.Region == "Kenya") %>%
  dplyr::filter(cases > 0) %>%
  dplyr::group_by(Country.Region, Province.State, 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$Stamen.Toner)
names(cv_data_for_plot.split) %>%
  purrr::walk(function(df2) {
    map_object <<- map_object %>%
      addCircleMarkers(
        data = cv_data_for_plot.split[[df2]],
        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[[df2]],
          feature.id = FALSE,
          row.numbers = FALSE,
          zcol = c("type", "cases", "Country.Region", "Province.State")
        ),
        group = df2,
        #                 clusterOptions = markerClusterOptions(removeOutsideVisibleBounds = F),
        labelOptions = labelOptions(
          noHide = F,
          direction = "auto"
        )
      )
  })

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





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

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

This dashboard provides an overview of the 2019 Novel Coronavirus COVID-19 (2019-nCoV) epidemic for Kenya. 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:**
 [GitHub](https://github.com/CarlvinJerry/COVID-19-Ke/blob/master/CovidKe.Rmd){target="_blank"}.

**Data:**
 [`{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:

```
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"}.

[Reach out](https://beyondrawdata.rbind.io/#contact) for any comments or feedback.

**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")`.