Map

Column

Districts with Covid-19 cases | Sunday January 17, 2021 | Clinty

Covid-19 infection and recovery | Bivariate choropleth

Summary

Row

confirmed

11,785

death

300 (1.5%)

recovered

5,992

active

1,434

tested

100,801

Row

Daily cumulative cases | Malawi

Comparison

Column

Cases distribution by type in districts

Cases distribution by type in neighboring countries

Trend

column

Daily new confirmed cases

Daily new death cases

About

The Covid-19 Dashboard for Malawi

This Covid-19 dashboard for Malawi has been developed to build awareness and pass the message to kick out Covid-19, and is actively supporting awareness campaigns led by World Health Organization, Malawi Ministry of Health, Public Health Institute of Malawi, UNICEF and many others.

Through open-source GIS and statistical software, I am delighted to support health organizations to raise awareness on Covid-19 pandemic. This dashboard is helping the public access up-to-date, high resolution, district-level geospatial information on spread of the pandemic.

By giving users visibility into their local situation, this dashboard has demonstrated that geovisualization of global crises such as infectious diseases can be enlightening, empowering, and can help curb the spread of online misinformation. Considering that lack of access to verified health information can be particularly harmful, spatial epidemiology information should be made available to public regarding status, spread and risk of infection of pandemics and other diseases of national and global importance.

Understanding COVID-19 situation in a country is important to prevent panic and helps the public make informed decisions and comply with the measures for containment and mitigation mandated by the government. A good understanding of the spread of COVID-19 in space and time is essential for its mitigation, as it helps to clarify the extent and impact of the pandemic and can aid decision making, planning and community action.

This project has shown that GIS is powerful and relevant in analyzing geographical distribution of diseases, and has the potential to raise public awareness, create opportunities for exchanging data and health-related messages, which in turn inspires new reflections on pandemics by the spatial epidemiologists and end-users.

I have no doubt that with this type of support coupled with campaigns promoting hand sanitizing, masking up, physical distancing, coughing etiquette and isolating if feeling unwell, together we will win.

This dashboard is built with R using the R Markdown framework and was adapted from this dashboard by Rami Krispin.

Data

The input data for this dashboard is available from my GitHub repository .

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 Saturday January 16, 2021 and the dashboard has been updated on Sunday January 17, 2021

---
title: "Covid-19 Cases in Malawi" 
author: "Clinton Nkolokosa"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    source_code: embed
    vertical_layout: fill
---

```{r setup, include=FALSE}
#------------------ Packages ------------------
library(flexdashboard)
library(devtools)
library(coronavirus)
library(leaflet)
library(leafpop)
library(purrr)
library(rgdal)
library(rgeos)
library(dplyr)
library(leaflet)
library(leaflet.extras)
library(htmltools)
library(tidyverse)
library(RColorBrewer)
library(scales)
library(lubridate)
library(visdat)
library(sf)
library(httr)
library(jsonlite) 
library(biscale)
library(cowplot)

`%>%` <- magrittr::`%>%`

#------------------ Parameters ------------------
# Set colors
# https://www.w3.org/TR/css-color-3/#svg-color
confirmed_color <- "purple"
active_color <- "orange"
recovered_color <- "forestgreen"
death_color <- "red"
tested_color <- "teal"

#------------------ Dataset ------------------
df <- coronavirus %>%
  dplyr::filter(country == "Malawi") %>%
  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(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 == "Malawi") %>%
  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) %>%
  dplyr::mutate(
    confirmed_cum = cumsum(confirmed),
    death_cum = cumsum(death),
    active_cum = cumsum(active),
    recovered_cum = cumsum(recovered))


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

setwd("~/R/Covid visualisation/R")

# District boundary shapefile for Malawi
d<-readOGR(dsn = getwd(),layer = "census_dist")

cd<-read.csv("Covid cases per district (copy).csv") %>% 
  mutate(active_cases= Confirmed-(Deaths+Recovered))

dist<-merge(d,cd,by.x="fid",by.y="Fid")


covid <- read_csv("https://raw.githubusercontent.com/datasets/covid-19/master/data/time-series-19-covid-combined.csv")

# daily_confirmed <- read.csv("owid-covid-data.csv") %>% 
#   dplyr::filter(location == "Malawi")
daily_confirmed <- read.csv("https://raw.githubusercontent.com/owid/covid-19-data/master/public/data/owid-covid-data.csv", sep = ",") 

daily_confirmed <-  daily_confirmed %>% 
  dplyr::filter(location == "Malawi")
  
daily_confirmed$date <- as.Date(daily_confirmed$date)

# Recent case
mw_total_last <- daily_confirmed %>% dplyr::filter(date == max(date)-1)

daily_confirmed <- daily_confirmed %>% 
  dplyr::arrange(date) %>%
  dplyr::mutate(tested_daily = total_tests - dplyr::lag(total_tests, n = 1),
                daily_new_cases = c(NA,diff(daily_confirmed$cumulative_cases)))

daily_confirmed$tested_daily[1] <- daily_confirmed$total_tests[1]

# Remove unnecessary Columns and Rename
covid <- covid %>% 
  select(Date,country=`Country/Region`, Confirmed, Recovered,Deaths)

# Create a useful data frame
covid_stat<- covid %>% 
  group_by(country) %>% 
  summarise(Death=max(Deaths),Confirmed =max(Confirmed), Recovered=max(Recovered)) %>% 
  mutate(Active_case = Confirmed - Recovered)

vis_miss(covid_stat)

```



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

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

### **Districts with Covid-19 cases** | `r format(Sys.time(), "%A %B %d, %Y")` | Clinty  

```{r}

df <- coronavirus %>%
  dplyr::filter(country == "Malawi" |
    country == "Zambia" |
    country == "Tanzania" |
    country == "Mozambique") %>%
  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(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))

bar<-plotly::plot_ly(
  data = df,
  x = ~country,
  y = ~ confirmed,
  type = "bar",
  name = "Confirmed",
  marker = list(color = active_color)
) %>%
  plotly::add_trace(
    y = ~death,
    name = "Death",
    marker = list(color = death_color)
  ) %>%
  plotly::add_trace(
    y = ~recovered,
    name = "Recovered",
    marker = list(color = recovered_color)
  ) %>% 
  plotly::layout(
    barmode = "stack",
    yaxis = list(title = "Total cases"),
    xaxis = list(title = ""),
    hovermode = "compare",
    margin = list(
      b = 10,
      t = 10,
      pad = 2
    )
  )

# Map title using CSS styles and HTML
title<-tags$style(HTML(".map-title{
                  transform:translate(-10%,20%);position:fixed!important;
                  left:10%;text-align:left;padding-left:10px;
                  padding-right:10px;background:rgba(255,255,255,0.75);
                  font-weight:bold;font-size:15px}"))

leaflettitle<-tags$div(title, HTML("Matenda a Corona virus ndi opeweka"))

bins <- c(0,5,10,50,100,500,1000,1500,2000,2500)
pal <- colorBin("YlOrRd",domain = dist, bins = bins)

labels<-paste("

Covid-19 cases

", "",cd$District,"
", "Confirmed:",cd$Confirmed,"
", "Deaths:",cd$Deaths,"
", "Recovered:",cd$Recovered,"
", "Active cases:",cd$active_cases,"
", sep = " ") covid_map<-leaflet() %>% setView(lng = 33.7,lat = -13.9, zoom= 6) %>% addProviderTiles(providers$CartoDB)%>% addPolygons(data = dist, group = "active_cases", weight = 1, smoothFactor = 1, color = "gray", fillOpacity = 1, fillColor =~pal(active_cases), label = lapply(labels,HTML)) %>% addPolygons(data = dist, group = "Confirmed", weight = 1, smoothFactor = 1, color = "gray", fillOpacity = 1, fillColor =~pal(Confirmed), label = lapply(labels,HTML)) %>% addPolygons(data = dist, group = "Deaths", weight = 1, smoothFactor = 1, color = "gray", fillOpacity = 1, fillColor =~pal(Deaths), label = lapply(labels,HTML)) %>% addPolygons(data = dist, group = "Recovered", weight = 1, smoothFactor = 1, color = "gray", fillOpacity = 1, fillColor =~pal(Recovered), label = lapply(labels,HTML)) %>% addLayersControl(baseGroups = c("Confirmed", "Active", "Deaths","Recovered"), options = layersControlOptions(collapsed = FALSE)) %>% addLegend(pal = pal, values = c(1:2500), opacity = 0.7, title = 'Covid-19 Cases', position = 'bottomright') %>% addScaleBar(position= 'bottomleft') %>% addControl(leaflettitle,position = "topleft",className = "map-title") covid_map ``` ### **Covid-19 infection and recovery** | Bivariate choropleth ```{r, fig.width=6, fig.height=10} pop_covid_data <- read.csv("pop_density.csv") %>% select(fid, PopDensityPerc, CovidConfirmedPerc, recovered_perc) mwdistrict <- read_sf("census_dist.shp") mwdist<-merge(mwdistrict, pop_covid_data ,by.x="fid",by.y="fid") all_data <- bi_class(mwdist, x = recovered_perc, y = CovidConfirmedPerc, style = "quantile", dim = 3) bivariate_map <- ggplot() + geom_sf(data = all_data, mapping = aes(fill = bi_class), color = "white", size = 0.1, show.legend = FALSE) + bi_scale_fill(pal = "DkBlue", dim = 3) + coord_sf(crs = st_crs(4326), datum = NA) + theme_void() + theme(plot.margin = unit(c(1,1,1,1), "cm"), plot.title = element_text(size = 18, face = "bold", hjust = 0.5), plot.caption = element_text(size = 9, color = "grey50", hjust = 1, margin = margin(t = 15))) legend <- bi_legend(pal = "DkBlue", dim = 3, xlab = "High Covid-19 recovery", ylab = "High Covid-19 infection", size = 13) #Legend for Map The legend above describes how each of the colored values combine to present information on whether the selected two variables tend to be in agreement or disagreement. Dark blue, or the upper right corner, indicates that values are both high and in agreement. plot <- ggdraw() + draw_plot(bivariate_map, 0, 0, 1, 1) + draw_plot(legend, 0.01, 0.02, 0.4, 0.4, scale = 1.2) plot ``` Summary ======================================================================= Row {data-width=400} ----------------------------------------------------------------------- ### confirmed {.value-box} ```{r} d <-df %>% filter(country == "Malawi") valueBox(value = paste(format(sum(d$confirmed), big.mark = ","), "", sep = " "), caption = "Total confirmed cases", icon = "fas fa-user-md", color = confirmed_color) ``` ### death {.value-box} ```{r} valueBox(value = paste(format(sum(d$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 = "", color = death_color) ``` ### recovered {.value-box} ```{r} valueBox(value = paste(format(sum(d$recovered, na.rm = TRUE), big.mark = ","), " ", sep = ""), caption = "Total recovered cases", icon = "fas fa-heartbeat", color = recovered_color) ``` ### active {.value-box} ```{r} valueBox(value = paste(format(sum(cd$active_cases, na.rm = TRUE), big.mark = ",")," ", sep = ""), caption = "Active cases", icon = "fas fa-ambulance", color = active_color) ``` ### tested {.value-box} ```{r} valueBox(value = paste(format(mw_total_last$total_tests, big.mark = ","), "", sep = " "), caption = "Total tested", icon = "fas fa-hospital", color = tested_color) ``` Row ----------------------------------------------------------------------- ### **Daily cumulative cases** | Malawi ```{r} plotly::plot_ly(data = df_daily) %>% plotly::add_trace( x = ~date, y = ~confirmed_cum, type = "scatter", mode = "lines+markers", 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_trace( x = ~date, y = ~recovered_cum, type = "scatter", mode = "lines+markers", name = "Recovered", line = list(color = recovered_color), marker = list(color = recovered_color) ) %>% 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} ------------------------------------- ### **Cases distribution by type in districts** ```{r} cd %>% filter(District != "Zomba City", District != "Lilongwe", District != "Blantyre") %>% plotly::plot_ly( y = ~ District, x = ~ Confirmed, type = "bar", orientation = 'h', name = "Confirmed", marker = list(color = confirmed_color) ) %>% plotly::add_trace( x = ~ Deaths, name = "Death", marker = list(color = death_color) ) %>% plotly::add_trace( x = ~ Recovered, name = "Recovered", marker = list(color = recovered_color) ) %>% plotly::add_trace( x = ~ active_cases, name = "Active", marker = list(color = active_color) ) %>% plotly::layout( barmode = "stack", xaxis = list(title = "Total cases"), yaxis = list(title = ""), hovermode = "compare", margin = list( b = 10, t = 10, pad = 2 ) ) ``` ### **Cases distribution by type in neighboring countries ** ```{r daily_summary} df <- coronavirus %>% dplyr::filter(country == "Malawi" | country == "Zambia" | country == "Tanzania" | country == "Mozambique") %>% 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(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, x = ~country, y = ~ confirmed, type = "bar", name = "Confirmed", marker = list(color = confirmed_color) ) %>% plotly::add_trace( y = ~death, name = "Death", marker = list(color = death_color) ) %>% plotly::add_trace( y = ~recovered, name = "Recovered", marker = list(color = recovered_color) ) %>% plotly::layout( barmode = "stack", yaxis = list(title = "Total cases"), xaxis = list(title = ""), hovermode = "compare", margin = list( b = 10, t = 10, pad = 2 ) ) ``` Trend ======================================================================= column ------------------------------------------- ### Daily new confirmed cases ```{r} plotly::plot_ly(data = daily_confirmed, x = ~ date, y = ~ c(NA,diff(daily_confirmed$total_cases)), type = "scatter", mode = "markers", marker = list(color = confirmed_color), name = "Positive Cases") %>% plotly::add_lines(x = ~ date, y = ~ new_cases_smoothed, line = list(color = "grey", width = 3), name = "Trend Line") %>% plotly::layout(title = "", legend = list(x = 0.6, y = 0.9), yaxis = list(title = "Number of Cases"), xaxis = list(title = "Using 5 days trailing moving average to calculate the trend line"), hovermode = "compare") ``` ### Daily new death cases ```{r} plotly::plot_ly(data = daily_confirmed, x = ~ date, y = ~ c(NA,diff(daily_confirmed$total_deaths)), type = "scatter", mode = "markers", marker = list(color = death_color), name = "Death Cases") %>% plotly::add_lines(x = ~ date, y = ~ new_deaths_smoothed, line = list(color = "grey", width = 3), name = "Trend Line") %>% plotly::layout(title = "", legend = list(x = 0.6, y = 0.9), yaxis = list(title = "Number of Cases"), xaxis = list(title = "Using 5 days trailing moving average to calculate the trend line"), hovermode = "compare") ``` About ======================================================================= **The Covid-19 Dashboard for Malawi** This [Covid-19 dashboard for Malawi](https://rpubs.com/Clinty) has been developed to build awareness and pass the message to kick out Covid-19, and is actively supporting awareness campaigns led by World Health Organization, Malawi Ministry of Health, Public Health Institute of Malawi, UNICEF and many others. Through open-source GIS and statistical software, I am delighted to support health organizations to raise awareness on Covid-19 pandemic. This [dashboard](https://rpubs.com/Clinty) is helping the public access up-to-date, high resolution, district-level geospatial information on spread of the pandemic. By giving users visibility into their local situation, this dashboard has demonstrated that geovisualization of global crises such as infectious diseases can be enlightening, empowering, and can help curb the spread of online misinformation. Considering that lack of access to verified health information can be particularly harmful, spatial epidemiology information should be made available to public regarding status, spread and risk of infection of pandemics and other diseases of national and global importance. Understanding COVID-19 situation in a country is important to prevent panic and helps the public make informed decisions and comply with the measures for containment and mitigation mandated by the government. A good understanding of the spread of COVID-19 in space and time is essential for its mitigation, as it helps to clarify the extent and impact of the pandemic and can aid decision making, planning and community action. This project has shown that GIS is powerful and relevant in analyzing geographical distribution of diseases, and has the potential to raise public awareness, create opportunities for exchanging data and health-related messages, which in turn inspires new reflections on pandemics by the spatial epidemiologists and end-users. I have no doubt that with this type of support coupled with campaigns promoting hand sanitizing, masking up, physical distancing, coughing etiquette and isolating if feeling unwell, together we will win. This dashboard is built with R using the R Markdown framework and was adapted from this [dashboard](https://ramikrispin.github.io/coronavirus_dashboard/){target="_blank"} by Rami Krispin. **Data** The input data for this dashboard is available from my [`GitHub repository`](https://github.com/ClintyNkolokosa/Covid-19-analysis-and-visualisation){target="_blank"} . 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")` ```{r} #knitr::include_graphics("flag-400.png") ```