adjusted all scripts to dynamically generate dates for subtitles and captions
This commit is contained in:
parent
e5017e9e8a
commit
4240921ada
6 changed files with 55 additions and 21 deletions
|
@ -20,10 +20,11 @@ library(parallel)
|
|||
## Load TOPS data ----
|
||||
## load TOPS data for the whole state (crashes involving bikes and pedestrians),
|
||||
TOPS_data <- as.list(NULL)
|
||||
for (file in list.files(path = "data/TOPS", pattern = "crash-data-download")) {
|
||||
for (file in list.files(path = "data/TOPS/", pattern = "crash-data-download")) {
|
||||
message(paste("importing data from file: ", file))
|
||||
year <- substr(file, 21, 24)
|
||||
csv_run <- read_csv(file = paste0("data/TOPS/",file), col_types = cols(.default = "c"))
|
||||
csv_run["retreive_date"] <- file.info(file = paste0("data/TOPS/",file))$mtime
|
||||
TOPS_data[[file]] <- csv_run
|
||||
}
|
||||
rm(csv_run, file, year)
|
||||
|
@ -39,6 +40,8 @@ TOPS_data <- TOPS_data %>%
|
|||
mutate(month = month(date, label = TRUE),
|
||||
year = as.factor(year(date)))
|
||||
|
||||
retrieve_date <- max(TOPS_data %>% filter(year %in% max(year(TOPS_data$date), na.rm = TRUE)) %>% pull(retreive_date))
|
||||
|
||||
# county index
|
||||
counties <- data.frame(name = c("Dane", "Milwaukee"),
|
||||
CNTYCODE = c(13, 40),
|
||||
|
@ -143,7 +146,10 @@ for(county in county_focus) {
|
|||
" County"),
|
||||
x = "Year",
|
||||
y = "Number of crashes",
|
||||
caption = "data from UW TOPS Laboratory")
|
||||
caption = paste0("crash data from UW TOPS lab - retrieved ",
|
||||
strftime(retrieve_date, format = "%m/%Y"),
|
||||
" per direction of the WisDOT Bureau of Transportation Safety",
|
||||
"\nbasemap from StadiaMaps and OpenStreetMap Contributers"))
|
||||
ggsave(file = paste0("figures/school_maps/Crash Maps/",
|
||||
str_to_title(county),
|
||||
" County/_",
|
||||
|
@ -292,7 +298,10 @@ for(district in district_focus) {
|
|||
min(year(TOPS_data$date), na.rm = TRUE),
|
||||
" - ",
|
||||
max(year(TOPS_data$date), na.rm = TRUE)),
|
||||
caption = "crash data from UW TOPS lab - retrieved 3/2024 per direction of the WisDOT Bureau of Transportation Safety\nbasemap from StadiaMaps and OpenStreetMap Contributers",
|
||||
caption = paste0("crash data from UW TOPS lab - retrieved ",
|
||||
strftime(retrieve_date, format = "%m/%Y"),
|
||||
" per direction of the WisDOT Bureau of Transportation Safety",
|
||||
"\nbasemap from StadiaMaps and OpenStreetMap Contributers"),
|
||||
x = NULL,
|
||||
y = NULL) +
|
||||
theme(axis.text=element_blank(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue