made initial data and basemap downloads automatic
This commit is contained in:
parent
9e2ad25e15
commit
711be5f1c2
16
COVID.R
16
COVID.R
@ -5,12 +5,14 @@ library(lubridate)
|
||||
library(ggmap)
|
||||
library(ggrepel)
|
||||
|
||||
setwd(paste0("~/",
|
||||
ifelse(Sys.info()['nodename'] == "pseudotsuga", "Documents", "Nextcloud"),
|
||||
"/dataProjects/COVID"))
|
||||
setwd("~/Documents/dataProjects/COVID")
|
||||
|
||||
#download data ----
|
||||
if(file.exists("data_download_time.Rda")) {
|
||||
load("data_download_time.Rda")
|
||||
} else {
|
||||
downloaded_dttm <- ymd_hms('1900_01_01:00:00:00')
|
||||
}
|
||||
|
||||
if(as.double(difftime(downloaded_dttm, Sys.time()), units = "hours") < -2){
|
||||
|
||||
@ -263,10 +265,10 @@ buffer <- 0.1
|
||||
states <- c("Washington", "Wisconsin", "Illinois")
|
||||
max_county_value <- max(us_county_data %>% filter(state %in% states) %>% pull(active_estimate), na.rm = TRUE)
|
||||
|
||||
#this if statement loads new basemap tiles only if marked as "TRUE", otherwise it loads the tiles from the file: /data/basemap.RData
|
||||
|
||||
for(i in 1:length(states)){
|
||||
if(FALSE){
|
||||
if(file.exists(paste0("data/", states[i], "_basemap.RData"))){
|
||||
load(file = paste0("data/", states[i], "_basemap.RData"))
|
||||
} else {
|
||||
range <- c(left = min(us_county_map %>% filter(state %in% states[i]) %>% pull(long), na.rm = TRUE) - buffer,
|
||||
bottom = min(us_county_map %>% filter(state %in% states[i]) %>% pull(lat), na.rm = TRUE) - buffer,
|
||||
right = max(us_county_map %>% filter(state %in% states[i]) %>% pull(long), na.rm = TRUE) + buffer,
|
||||
@ -276,8 +278,6 @@ for(i in 1:length(states)){
|
||||
zoom = 8,
|
||||
maptype = "toner-hybrid")
|
||||
save(basemap, file = paste0("data/", states[i], "_basemap.RData"))
|
||||
} else {
|
||||
load(file = paste0("data/", states[i], "_basemap.RData"))
|
||||
}
|
||||
|
||||
ggmap(basemap) +
|
||||
|
Loading…
x
Reference in New Issue
Block a user