Introduction

In this assignment we will be mapping COVID-19 data.

OUr first step is to download the data from the Johns Hopkins University Center for Systems Science and Engineering GitHub repository.

library(leaflet)
library(tidyverse)
library(glue)
library(knitr)


covid_data <- read_csv(
    'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv'
)

We rename a couple of the variables, then tidy up the data. The original data is in a wide format, with a column for each date between the 1/22/2020 and the 3/30/2020 (American style dates) which has the number of COVID-19 cases up until that point.

We gather these together into a long format, with a date column for the date and a number column for the number of cases per country.

covid_data %>%
    rename(
        country_or_region = `Country/Region`,
        province_or_state = `Province/State`,
        lat = Lat,
        lng = Long
    ) %>% 
    gather(date, number, c(`1/22/20`:`3/30/20`)) ->
    covid_data_long

head(covid_data_long) %>% kable()
province_or_state country_or_region lat lng 3/31/20 date number
NA Afghanistan 33.0000 65.0000 174 1/22/20 0
NA Albania 41.1533 20.1683 243 1/22/20 0
NA Algeria 28.0339 1.6596 716 1/22/20 0
NA Andorra 42.5063 1.5218 376 1/22/20 0
NA Angola -11.2027 17.8739 7 1/22/20 0
NA Antigua and Barbuda 17.0608 -61.7964 7 1/22/20 0

Mapping

We can now map the data for a specific date; I have picked a date in late March to view. We group by the relevant variables and sum the cases together. A ‘popup’ strong is then created by combining the country/region, the province/state, and the cases.

Finally, we create the leaflet map.

I

covid_data_long %>% 
    dplyr::filter(date == '3/30/20') %>% 
    group_by(country_or_region, province_or_state, lat, lng) %>% 
    summarise(cases = sum(number)) %>%
    mutate(
        popup = case_when(
            is.na(province_or_state) ~ as.character(glue('{country_or_region}: {cases}')),
            TRUE ~ as.character( glue('{country_or_region} / {province_or_state}: {cases}'))
        )
    ) %>% 
    leaflet() %>%
    addTiles() %>% 
    addMarkers(~lng, ~lat, popup = ~popup, clusterOptions = markerClusterOptions(showCoverageOnHover = FALSE))