Skip to content

Instantly share code, notes, and snippets.

@idshklein
Created January 15, 2023 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save idshklein/bd8d686e10bcea601cb7248345fe44a6 to your computer and use it in GitHub Desktop.
Save idshklein/bd8d686e10bcea601cb7248345fe44a6 to your computer and use it in GitHub Desktop.
pacman::p_load(tidyverse,jsonlite,lubridate,rayshader)
df_2019 <- read_json("https://data.gov.il/api/3/action/datastore_search?resource_id=5ed3ac9d-0709-46fb-aa42-1156682f3b85&limit=389&filters={%22OfficeLineId%22:%2224100%22}")
df_2020 <- read_json("https://data.gov.il/api/3/action/datastore_search?resource_id=6042d958-d86f-40bc-803b-2c5620d90394&limit=392&filters={%22OfficeLineId%22:%2224100%22}")
df_2021 <- read_json("https://data.gov.il/api/3/action/datastore_search?resource_id=09de377b-6462-48d5-8470-177c17016f6e&limit=405&filters={%22OfficeLineId%22:%2224100%22}")
df_2022 <- read_json("https://data.gov.il/api/3/action/datastore_search?resource_id=bfd22231-7a8b-4fc0-91bd-342397860ab5&limit=440&filters={%22OfficeLineId%22:%2224100%22}")
dfis <- function(df){df$result$records %>% map_df(~.x)}
dfis(df_2019) %>%
bind_rows(dfis(df_2020)) %>%
bind_rows(dfis(df_2021)) %>%
mutate_all(as.character) %>%
bind_rows(dfis(df_2022) %>%
rename_at(12:42, ~substring(., 2)) %>%
mutate_all(as.character)) %>%
gather(day,val, 12:42) %>%
mutate(date = dmy(paste(day,month_key,year_key,sep = "/")),
hour_a = fct_inseq(factor(as.numeric(hour_a))),
val = as.numeric(val)) %>%
filter(!is.na(date)) %>% {
(.) %>% ggplot(aes(x=date,y=hour_a, fill = val )) +
geom_tile() +
facet_grid(Direction~.)
} %>%
plot_gg()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment