diff --git a/.gitignore b/.gitignore index 6ed82b1..7eb9b56 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,3 @@ data-bkup archive/ trash/ api_key -R/route_analysis.html diff --git a/R/route_analysis.Rmd b/R/route_analysis.Rmd index 53d4bed..0a1729a 100644 --- a/R/route_analysis.Rmd +++ b/R/route_analysis.Rmd @@ -7,8 +7,6 @@ output: toc_float: collapsed: false smooth_scroll: true -editor_options: - chunk_output_type: console --- ```{r libs, eval = TRUE, echo = TRUE, results = "show", warning = FALSE, error = TRUE, message = FALSE} @@ -53,7 +51,7 @@ register_stadiamaps(key = substr(read_file(file = "api_keys/stadia_api_key"), 1, ## subset addresses within 1.5 miles walk_boundary_poly <- fill_holes(st_make_valid(osrmIsodistance( - loc = WI_schools %>% filter(NCES_CODE %in% school_focus$NCES_CODE), + loc = st_transform(WI_schools %>% filter(NCES_CODE %in% school_focus$NCES_CODE), crs = 4326), breaks = c(walk_boundary_m), res = 80) ), units::set_units(1, km^2)) @@ -62,12 +60,8 @@ addresses_near <- st_intersection(addresses, walk_boundary_poly) ## load bike tls bike_lts <- st_read("data/bike_lts/bike_lts_DANE.geojson") -# make lts attribute a factor bike_lts[["lts"]] <- as.factor(bike_lts$LTS_F) -# remove segments with an LTS value of 9 -bike_lts <- bike_lts %>% filter(lts != 9) -# set color scale bike_lts_scale <- data.frame(code = c(1, 2, 3, 4, 9), color = c("#1a9641", "#a6d96a", @@ -100,7 +94,7 @@ logo <- image_read(path = "other/BFW_Logo_180_x_200_transparent_background.png") school_symbol <- image_read_svg(path = "other/school_FILL0_wght400_GRAD0_opsz24.svg") -bbox <- st_bbox(st_buffer(walk_boundary_poly, dist = 500)) +bbox <- st_bbox(st_transform(st_buffer(walk_boundary_poly, dist = 500), crs = 4326)) bbox <- c(left = as.double(bbox[1]), bottom = as.double(bbox[2]), right = as.double(bbox[3]), @@ -136,11 +130,11 @@ ggmap(basemap) + scale_linewidth_continuous(range = c(0, 3)) + annotation_raster(school_symbol, # Position adjustments here using plot_box$max/min/range - ymin = as.double((WI_schools %>% filter(NCES_CODE %in% school_focus$NCES_CODE) %>% pull(geom))[[1]])[2] - 0.001, - ymax = as.double((WI_schools %>% filter(NCES_CODE %in% school_focus$NCES_CODE) %>% pull(geom))[[1]])[2] + 0.001, - xmin = as.double((WI_schools %>% filter(NCES_CODE %in% school_focus$NCES_CODE) %>% pull(geom))[[1]])[1] - 0.0015, - xmax = as.double((WI_schools %>% filter(NCES_CODE %in% school_focus$NCES_CODE) %>% pull(geom))[[1]])[1] + 0.0015) + - geom_sf_label(data = WI_schools %>% filter(NCES_CODE %in% school_focus$NCES_CODE), + ymin = as.double((st_transform(WI_schools %>% filter(NCES_CODE %in% school_focus$NCES_CODE), crs = 4326) %>% pull(geom))[[1]])[2] - 0.001, + ymax = as.double((st_transform(WI_schools %>% filter(NCES_CODE %in% school_focus$NCES_CODE), crs = 4326) %>% pull(geom))[[1]])[2] + 0.001, + xmin = as.double((st_transform(WI_schools %>% filter(NCES_CODE %in% school_focus$NCES_CODE), crs = 4326) %>% pull(geom))[[1]])[1] - 0.0015, + xmax = as.double((st_transform(WI_schools %>% filter(NCES_CODE %in% school_focus$NCES_CODE), crs = 4326) %>% pull(geom))[[1]])[1] + 0.0015) + + geom_sf_label(data = st_transform(WI_schools %>% filter(NCES_CODE %in% school_focus$NCES_CODE), crs = 4326), inherit.aes = FALSE, mapping = aes(label = school_focus %>% pull(name)), nudge_y = 0.0015, @@ -184,11 +178,11 @@ ggmap(basemap) + scale_linewidth_continuous(range = c(0, 3)) + annotation_raster(school_symbol, # Position adjustments here using plot_box$max/min/range - ymin = as.double((WI_schools %>% filter(NCES_CODE %in% school_focus$NCES_CODE) %>% pull(geom))[[1]])[2] - 0.001, - ymax = as.double((WI_schools %>% filter(NCES_CODE %in% school_focus$NCES_CODE) %>% pull(geom))[[1]])[2] + 0.001, - xmin = as.double((WI_schools %>% filter(NCES_CODE %in% school_focus$NCES_CODE) %>% pull(geom))[[1]])[1] - 0.0015, - xmax = as.double((WI_schools %>% filter(NCES_CODE %in% school_focus$NCES_CODE) %>% pull(geom))[[1]])[1] + 0.0015) + - geom_sf_label(data = WI_schools %>% filter(NCES_CODE %in% school_focus$NCES_CODE), + ymin = as.double((st_transform(WI_schools %>% filter(NCES_CODE %in% school_focus$NCES_CODE), crs = 4326) %>% pull(geom))[[1]])[2] - 0.001, + ymax = as.double((st_transform(WI_schools %>% filter(NCES_CODE %in% school_focus$NCES_CODE), crs = 4326) %>% pull(geom))[[1]])[2] + 0.001, + xmin = as.double((st_transform(WI_schools %>% filter(NCES_CODE %in% school_focus$NCES_CODE), crs = 4326) %>% pull(geom))[[1]])[1] - 0.0015, + xmax = as.double((st_transform(WI_schools %>% filter(NCES_CODE %in% school_focus$NCES_CODE), crs = 4326) %>% pull(geom))[[1]])[1] + 0.0015) + + geom_sf_label(data = st_transform(WI_schools %>% filter(NCES_CODE %in% school_focus$NCES_CODE), crs = 4326), inherit.aes = FALSE, mapping = aes(label = school_focus %>% pull(name)), nudge_y = 0.0015, @@ -228,11 +222,11 @@ ggmap(basemap) + new_scale_color() + annotation_raster(school_symbol, # Position adjustments here using plot_box$max/min/range - ymin = as.double((WI_schools %>% filter(NCES_CODE %in% school_focus$NCES_CODE) %>% pull(geom))[[1]])[2] - 0.001, - ymax = as.double((WI_schools %>% filter(NCES_CODE %in% school_focus$NCES_CODE) %>% pull(geom))[[1]])[2] + 0.001, - xmin = as.double((WI_schools %>% filter(NCES_CODE %in% school_focus$NCES_CODE) %>% pull(geom))[[1]])[1] - 0.0015, - xmax = as.double((WI_schools %>% filter(NCES_CODE %in% school_focus$NCES_CODE) %>% pull(geom))[[1]])[1] + 0.0015) + - geom_sf_label(data = WI_schools %>% filter(NCES_CODE %in% school_focus$NCES_CODE), + ymin = as.double((st_transform(WI_schools %>% filter(NCES_CODE %in% school_focus$NCES_CODE), crs = 4326) %>% pull(geom))[[1]])[2] - 0.001, + ymax = as.double((st_transform(WI_schools %>% filter(NCES_CODE %in% school_focus$NCES_CODE), crs = 4326) %>% pull(geom))[[1]])[2] + 0.001, + xmin = as.double((st_transform(WI_schools %>% filter(NCES_CODE %in% school_focus$NCES_CODE), crs = 4326) %>% pull(geom))[[1]])[1] - 0.0015, + xmax = as.double((st_transform(WI_schools %>% filter(NCES_CODE %in% school_focus$NCES_CODE), crs = 4326) %>% pull(geom))[[1]])[1] + 0.0015) + + geom_sf_label(data = st_transform(WI_schools %>% filter(NCES_CODE %in% school_focus$NCES_CODE), crs = 4326), inherit.aes = FALSE, mapping = aes(label = school_focus %>% pull(name)), nudge_y = 0.0015,