Get the “Coronavirus Source Data” https://ourworldindata.org/coronavirus-source-data 59930 + observations of 55 variables. From different countries (“location”) in the world, with many different metrics. Each “date” is a different observation.
file_loc <- 'https://covid.ourworldindata.org/data/owid-covid-data.csv'
download.file(file_loc,"covid_data.csv")
covid_data <- read.csv("covid_data.csv")
library(lubridate)
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
covid_data$date <- ymd(covid_data$date)
recent_date <- max(covid_data$date)
recent_data <- covid_data[covid_data$date == recent_date-1,] #191 observations of 55 variables
recent_data <- recent_data[!(recent_data$location == "World"),]#190 observations
#head(recent_data)
# install.packages("tidygeocoder")
require("tidygeocoder")
## Loading required package: tidygeocoder
library(tidygeocoder)
library(profvis) # to get pause
countries <- as.character(recent_data$location )
#recent_data$lat <- 0 #initialize
#recent_data$long <- 0
country_lat_long <- geo(country = countries,method = "osm") #takes a couple minutes for all countries. Better to save it after, but this is how I got the lat/long
colnames(country_lat_long)[1]<- "location" #change the column name for country
recent_data<-Reduce(merge,list(recent_data,country_lat_long))
Will be making maps from leaflet
library(leaflet)
#my_map <- leaflet()
recent_data %>% leaflet() %>% addTiles() %>% addCircles(weight = 1,radius = 300*(recent_data$total_deaths_per_million))%>% addCircles(weight = 1,radius = 30*(recent_data$total_deaths_per_million))
## Assuming "long" and "lat" are longitude and latitude, respectively
## Warning in validateCoords(lng, lat, funcName): Data contains 4 rows with either
## missing or invalid lat/lon values and will be ignored
## Assuming "long" and "lat" are longitude and latitude, respectively
## Warning in validateCoords(lng, lat, funcName): Data contains 4 rows with either
## missing or invalid lat/lon values and will be ignored