In this project I am creating an interative map using R Markdown and Leaflet of the COVID-19 outbreak using April 9th, 2020 data. Data was taken from the 2019 Novel Coronavirus COVID-19 (2019-nCoV) Data Repository by Johns Hopkins CSSE GitHub.
Sys.info()
## sysname release version nodename
## "Windows" "10 x64" "build 18363" "DESKTOP-DP7KPRO"
## machine login user effective_user
## "x86-64" "Derek" "Derek" "Derek"
library(leaflet)
## Warning: package 'leaflet' was built under R version 3.6.3
library(dplyr)
## Warning: package 'dplyr' was built under R version 3.6.3
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(tidyr)
## Warning: package 'tidyr' was built under R version 3.6.2
Downloading and reading in the data set.
url <- "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/04-09-2020.csv"
file <- "04-09-2020.csv"
download.file(url = url, destfile = file, method = "curl")
mapdata <- read.csv(file)
head(mapdata)
## FIPS Admin2 Province_State Country_Region Last_Update Lat
## 1 45001 Abbeville South Carolina US 2020-04-09 23:02:37 34.22333
## 2 22001 Acadia Louisiana US 2020-04-09 23:02:37 30.29506
## 3 51001 Accomack Virginia US 2020-04-09 23:02:37 37.76707
## 4 16001 Ada Idaho US 2020-04-09 23:02:37 43.45266
## 5 19001 Adair Iowa US 2020-04-09 23:02:37 41.33076
## 6 21001 Adair Kentucky US 2020-04-09 23:02:37 37.10460
## Long_ Confirmed Deaths Recovered Active Combined_Key
## 1 -82.46171 7 0 0 0 Abbeville, South Carolina, US
## 2 -92.41420 89 3 0 0 Acadia, Louisiana, US
## 3 -75.63235 11 0 0 0 Accomack, Virginia, US
## 4 -116.24155 447 5 0 0 Ada, Idaho, US
## 5 -94.47106 1 0 0 0 Adair, Iowa, US
## 6 -85.28130 6 0 0 0 Adair, Kentucky, US
str(mapdata)
## 'data.frame': 2911 obs. of 12 variables:
## $ FIPS : int 45001 22001 51001 16001 19001 21001 29001 40001 8001 16003 ...
## $ Admin2 : Factor w/ 1566 levels "","Abbeville",..: 2 3 4 5 6 6 6 6 7 7 ...
## $ Province_State: Factor w/ 138 levels "","Alabama","Alaska",..: 116 62 129 50 54 60 73 94 20 50 ...
## $ Country_Region: Factor w/ 184 levels "Afghanistan",..: 177 177 177 177 177 177 177 177 177 177 ...
## $ Last_Update : Factor w/ 35 levels "2020-02-23 11:19:02",..: 33 33 33 33 33 33 33 33 33 33 ...
## $ Lat : num 34.2 30.3 37.8 43.5 41.3 ...
## $ Long_ : num -82.5 -92.4 -75.6 -116.2 -94.5 ...
## $ Confirmed : int 7 89 11 447 1 6 11 25 417 1 ...
## $ Deaths : int 0 3 0 5 0 0 0 2 14 0 ...
## $ Recovered : int 0 0 0 0 0 0 0 0 0 0 ...
## $ Active : int 0 0 0 0 0 0 0 0 0 0 ...
## $ Combined_Key : Factor w/ 2911 levels ",,Belize",",,France",..: 10 11 12 13 14 15 16 17 18 19 ...
sum(is.na(mapdata$Lat))
## [1] 61
sum(is.na(mapdata$Long_))
## [1] 61
## I need to remove these rows that have null values in Lat and Long_ so that my leaflet app will work later on
mapdata_noNA <- as.data.frame(mapdata[!is.na(mapdata$Lat),])
dim(mapdata_noNA)
## [1] 2850 12
## Making the map with leaflet
map <- mapdata_noNA %>%
leaflet() %>%
addTiles() %>%
addCircleMarkers(lng= ~Long_,
lat= ~Lat,
radius = mapdata_noNA$Confirmed/2500,
fillOpacity = 0.7,
stroke = FALSE,
popup=paste(mapdata_noNA$Combined_Key, "<br>Confirmed Cases: ",
formatC(mapdata_noNA$Confirmed, format = "d", big.mark = ",")
)
)
map