Making a map of COVID-19 cases

Overview

I have added an interactive world map to my COVID-19 website using the leaflet package.

Using my existing data preprocessing setup, it was incredibly easy to set up the interactive map! This includes a popup that displays the latest information for the corresponding country.

leaflet(plot_data) %>%
  addTiles() %>% 
  addProviderTiles(providers$Esri.WorldImagery, group = "World Imagery") %>%
  addProviderTiles(providers$Stamen.TonerLite, group = "Toner Lite") %>%
  addCircles(
    lng = ~Longitude, lat = ~Latitude, weight = 1,
    radius = ~log(Deaths + 1) * radius_multiplier,
    popup = sprintf(
    paste(
      "<strong>%s</strong>",
      "<i>%s</i>",
      "Confirmed cases: %s",
      "Active cases: %s",
      "Death: %s",
      "Recovered: %s",
      sep = "</br>"),
    format(plot_data$Date, "%a %b %d"),
    plot_data$`Country/Region`,
    format(plot_data$Confirmed, big.mark = ","),
    format(plot_data$Active, big.mark = ","),
    format(plot_data$Deaths, big.mark = ","),
    format(plot_data$Recovered, big.mark = ","))
  )

A tweak

The one tweak I pulled is to automatically adjust the multiplier controlling the radius of each circle as a function of the death toll. The multiplier is computed so that the largest circle on the map has a radius of 200 kilometers. All other circles are resized proportionally using the same multiplier.

radius_multiplier <- 2E5 / max(sqrt(plot_data$Deaths), na.rm = TRUE)

Thanks for reading!

Related