Use the same area to search within. Generate an image of your map with a legend for both the WIC and grocery store layers.
Report the geocoding results in terms of % correctly geocoded. Use the Census bureau’s geocoding service.
library(mapview)
library(sf)
## Linking to GEOS 3.8.1, GDAL 3.2.1, PROJ 7.2.1; sf_use_s2() is TRUE
library(tidycensus)
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5 ✓ purrr 0.3.4
## ✓ tibble 3.1.6 ✓ dplyr 1.0.7
## ✓ tidyr 1.2.0 ✓ stringr 1.4.0
## ✓ readr 2.1.2 ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(sf)
library(tmap)
library(dplyr)
library(tmap)
library(ggplot2)
library(classInt)
library(patchwork)
library(tmaptools)
library(ggsn)
## Loading required package: grid
library(censusxy)
library(sysfonts)
library(readr)
addr <- read_csv("~/OneDrive - University of Texas at San Antonio/Applied Demography/First Year/Spring 2022/Dem 5093- Corey/Class_GIS/addr.csv")
## New names:
## * Source -> Source...1
## * Source -> Source...227
## * `` -> ...228
## Rows: 58 Columns: 228
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (170): Source...1, Date, Obsolescence Date, Business Name, Legal Name, P...
## dbl (45): Physical Address Number, Physical ZIP, Physical ZIP 4, Location E...
## lgl (12): Physical Post Direction, Mailing Post Direction, EIN, Importer or...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
addr <- addr[c(6, 12:14)]
names(addr) <- c("street", "city", "st", "zip")
head(addr)
## # A tibble: 6 × 4
## street city st zip
## <chr> <chr> <chr> <dbl>
## 1 919 Guadalupe St San Antonio TX 78207
## 2 160 Spencer Ln San Antonio TX 78201
## 3 107 Babcock Rd San Antonio TX 78201
## 4 2610 West Ave San Antonio TX 78201
## 5 3534 Fredericksburg Rd San Antonio TX 78201
## 6 2023 N Zarzamora St San Antonio TX 78201
library(censusxy)
results<-cxy_geocode(addr,
street = "street",
city = "city",
state ="st",
zip = "zip",
class="sf",
output = "simple")
## 27 rows removed to create an sf object. These were addresses that the geocoder could not match.
mapview::mapview(results, layer="Grocery Stores")
library(sf)
st_write(results, dsn="~/OneDrive - University of Texas at San Antonio/Applied Demography/First Year/Spring 2022/Dem 5093- Corey/Class_GIS/", layer="WIC Services & Grocery Stores", driver="ESRI Shapefile", delete_layer = T, update = T)
## Warning: 'update' is deprecated.
## Use 'append' instead.
## See help("Deprecated")
## Deleting layer `WIC Services & Grocery Stores' using driver `ESRI Shapefile'
## Updating layer `WIC Services & Grocery Stores' to data source `/Users/josephjaiyeola/Library/CloudStorage/OneDrive-UniversityofTexasatSanAntonio/Applied Demography/First Year/Spring 2022/Dem 5093- Corey/Class_GIS' using driver `ESRI Shapefile'
## Writing 31 features with 4 fields and geometry type Point.
## [1] 58
## [1] 31
## [1] 53.4
library(readr)
wic <- read_csv("~/OneDrive - University of Texas at San Antonio/Applied Demography/First Year/Spring 2022/Dem 5093- Corey/Class_GIS/wic.csv")
## New names:
## * Source -> Source...1
## * Source -> Source...227
## * `` -> ...228
## Rows: 102 Columns: 228
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (135): Source...1, Date, Obsolescence Date, Business Name, Legal Name, P...
## dbl (41): Physical Address Number, Physical ZIP, Location Employee Size, Ma...
## lgl (51): Physical Post Direction, Mailing Post Direction, Importer or Expo...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
wic <- wic[c(6, 12:14)]
names(wic) <- c("street", "city", "st", "zip")
head(wic)
## # A tibble: 6 × 4
## street city st zip
## <chr> <chr> <chr> <dbl>
## 1 6700 W Interstate 10 San Antonio TX 78201
## 2 6800 W Interstate 10 Ste 200 San Antonio TX 78201
## 3 527 N Leona St San Antonio TX 78207
## 4 1410 Guadalupe St Ste 222 San Antonio TX 78207
## 5 3703 Fredericksburg Rd San Antonio TX 78201
## 6 800 Dolorosa San Antonio TX 78207
library(censusxy)
results2<-cxy_geocode(wic,
street = "street",
city = "city",
state ="st",
zip = "zip",
class="sf",
output = "simple")
## 21 rows removed to create an sf object. These were addresses that the geocoder could not match.
mapview::mapview(results, layer="WIC Stores")
library(sf)
st_write(results2, dsn="~/OneDrive - University of Texas at San Antonio/Applied Demography/First Year/Spring 2022/Dem 5093- Corey/Class_GIS/", layer="WIC STORE", driver="ESRI Shapefile", delete_layer = T, update = T)
## Warning: 'update' is deprecated.
## Use 'append' instead.
## See help("Deprecated")
## Deleting layer `WIC STORE' using driver `ESRI Shapefile'
## Updating layer `WIC STORE' to data source `/Users/josephjaiyeola/Library/CloudStorage/OneDrive-UniversityofTexasatSanAntonio/Applied Demography/First Year/Spring 2022/Dem 5093- Corey/Class_GIS' using driver `ESRI Shapefile'
## Writing 81 features with 4 fields and geometry type Point.
## [1] 102
## [1] 81
## [1] 79.4