TX Walkability Scores

library(sf)
library(tigris)
library(hrbrthemes)
library(tidyverse)


# https://www.epa.gov/smartgrowth/smart-location-mapping#walkability
# https://catalog.data.gov/dataset/walkability-index

st_read("L:/00_Spatial/jsonMap/countries/us-states/TX-48-texas-counties.json") %>%
  st_set_crs(4326) %>%
  st_transform("+proj=longlat +datum=WGS84 +no_defs") -> texas
## Reading layer `cb_2015_texas_county_20m' from data source `L:\00_Spatial\jsonMap\countries\us-states\TX-48-texas-counties.json' using driver `GeoJSON'
## Simple feature collection with 254 features and 10 fields
## geometry type:  POLYGON
## dimension:      XY
## bbox:           xmin: -106.6351 ymin: 25.83999 xmax: -93.53163 ymax: 36.50085
## epsg (SRID):    NA
## proj4string:    NA
## Reading layer `cb_2015_maine_county_20m' from data source `/Users/hrbrmstr/books/30-day-map-challenge/data/me-counties.json' using driver `TopoJSON'
## Simple feature collection with 16 features and 10 fields
## geometry type:  MULTIPOLYGON
## dimension:      XY
## bbox:           xmin: -71.08434 ymin: 43.05975 xmax: -66.9502 ymax: 47.45684
## epsg (SRID):    NA
## proj4string:    NA

border <- st_union(texas)


### url = "ftp://newftp.epa.gov/EPADataCommons/OP/WalkabilityIndex.zip"
setwd("L:/00_Spatial/WalkabilityIndex/")
walkies <- st_read("Natl_WI.gdb", "WalkabilityIndex")
## Reading layer `WalkabilityIndex' from data source `L:\00_Spatial\WalkabilityIndex\Natl_WI.gdb' using driver `OpenFileGDB'
## Simple feature collection with 220653 features and 27 fields
## geometry type:  MULTIPOLYGON
## dimension:      XY
## bbox:           xmin: -179.2311 ymin: -14.60181 xmax: 179.8597 ymax: 71.44106
## epsg (SRID):    4326
## proj4string:    +proj=longlat +datum=WGS84 +no_defs
tx_walkies <- st_intersection(walkies, border)
#york_walkies <- st_intersection(me_walkies, york)
#me_walkies <- readRDS(here::here("me-walkies.rds"))
#york_walkies <- readRDS(here::here("york-walkies.rds"))

#rivers <- linear_water(state = "ME", "York", class="sf")
#water <- area_water(state = "ME", "York", class = "sf")
#rd <- roads(state = "ME", "York", class = "sf")




ggplot() +
  geom_sf(data = border, color = "black", size = 0.75, fill=NA) +
  geom_sf(data = tx_walkies, color = "white", size = 0.0725, aes(fill = WalkIndex)) +
  geom_sf(data = texas, color = "#2b2b2b", size = 0.25, fill = NA) +
  geom_sf_label(
    data = texas, aes(label = NAME), family = font_es_bold, size = 4, lineheight = 0.875,
    label.padding = unit(0.05, "lines"), label.size = 0, fill = "#ffffff33"
  ) +
  scale_fill_viridis_c(
    direction = -1, limits = c(0,20), name = "Walkability Index\n",
    breaks = seq(0, 20, 5), labels = c("0 (Nigh impassable)", 5, 10, 15, "20 (Very walkable)")
  ) +
  coord_sf(crs=albersusa::us_laea_proj, datum=NA) +
  labs(
    x = NULL, y = NULL,
    title = "Walkability (At The Macro-Level) In Texas",
    caption = "Data source: <ftp://newftp.epa.gov/EPADataCommons/OP/WalkabilityIndex.zip>"
  ) +
  theme_ipsum_es(grid="") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = c(0.85, 0.25)) +
  theme(legend.title = element_text(family = font_es_bold, hjust = 0.5)) +
  theme(legend.box.background = element_rect(color = "#2b2b2b", fill = "white"))