diff --git a/.DS_Store b/.DS_Store index 224a9ac..60022e4 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/make_readme_figures/testing_from_source.R b/make_readme_figures/testing_from_source.R new file mode 100644 index 0000000..2c82db6 --- /dev/null +++ b/make_readme_figures/testing_from_source.R @@ -0,0 +1,46 @@ + +library(dplyr) +library(googleway) +library(htmlwidgets) +library(plotwidgets) +library(png) +library(sf) +library(sp) +library(stringr) +library(webshot2) +library(raster) +library(ColorNameR) +library(schemr) +library(ggplot2) +library(geodata) + +files <- file.path("~", "Documents", "Github", "googletraffic", "R") |> + list.files(full.names = T, + pattern = "*.R") +for(file_i in files) source(file_i) + +nbo <- gadm(country = "KEN", level = 1, path = tempdir()) +nbo <- nbo[nbo$NAME_1 == "Nairobi",] %>% st_as_sf() + +# Make raster +r <- gt_make_raster_from_polygon(polygon = nbo, + zoom = 14, + google_key = google_key) + +## Plot +r_df <- rasterToPoints(r, spatial = TRUE) %>% as.data.frame() +names(r_df) <- c("value", "x", "y") + +p <- ggplot() + + geom_raster(data = r_df, + aes(x = x, y = y, + fill = as.factor(value))) + + labs(fill = "Traffic\nLevel") + + scale_fill_manual(values = c("green2", "orange", "red", "#660000")) + + coord_quickmap() + + theme_void() + + theme(plot.background = element_rect(fill = "white", color="white")) + +ggsave(p, filename = "~/Desktop/nbo_traffic.png", + height = 4, width = 5) +