In this homework assignment, I’ll be geocoding addresses of both grocery stores and WIC offices on the west side of San Antonio.
The addresses have already been downloaded from the AtoZ database, and are now loaded into R:
library(tidycensus)
library(tidyverse)
## -- Attaching packages --------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.2 v purrr 0.3.4
## v tibble 3.0.3 v dplyr 1.0.2
## v tidyr 1.1.1 v stringr 1.4.0
## v readr 1.3.1 v forcats 0.5.0
## -- Conflicts ------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(sf)
## Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
library(ggplot2)
library(readxl)
library(censusxy)
grocery_addr<-read_excel("C:/Users/hhx360/Google Drive (naslund.utsa@gmail.com)/School Files/School/MS Applied Demography/semesters/Spring 2021/DEM 7093 - GIS/Homework/Homework 5/west_side_grocery.xls")
## New names:
## * Source -> Source...1
## * Source -> Source...223
addr<-grocery_addr[c(6, 12:14)]
names(addr)<-c("street", "city", "st", "zip")
head(addr)
## # A tibble: 6 x 4
## street city st zip
## <chr> <chr> <chr> <chr>
## 1 646 S Flores St San Antonio TX 78204
## 2 1314 Fredericksburg Rd San Antonio TX 78201
## 3 1545 S San Marcos San Antonio TX 78207
## 4 4522 Fredericksburg Rd San Antonio TX 78201
## 5 1200 El Paso St San Antonio TX 78207
## 6 2902 Guadalupe St San Antonio TX 78207
wic_addr<-read_excel("C:/Users/hhx360/Google Drive (naslund.utsa@gmail.com)/School Files/School/MS Applied Demography/semesters/Spring 2021/DEM 7093 - GIS/Homework/Homework 5/west_side_wic.xls")
## New names:
## * Source -> Source...1
## * Source -> Source...223
wic_addr<-wic_addr[c(6, 12:14)]
names(wic_addr)<-c("street", "city", "st", "zip")
head(wic_addr)
## # A tibble: 6 x 4
## street city st zip
## <chr> <chr> <chr> <chr>
## 1 6800 W Interstate 10 Ste 200 San Antonio TX 78201
## 2 1410 Guadalupe St Ste 222 San Antonio TX 78207
## 3 527 N Leona St San Antonio TX 78207
## 4 1131 Babcock Rd Ste 125 San Antonio TX 78201
## 5 4522 Fredericksburg Rd Ste A45 San Antonio TX 78201
## 6 121 S Leona St San Antonio TX 78207
Now I use the censusxy package to actually geocode the addresses:
results<-cxy_geocode(addr,
street = "street",
city = "city",
state ="st",
zip = "zip",
class="sf",
output = "simple")
## 26 rows removed to create an sf object. These were addresses that the geocoder could not match.
wic_results<-cxy_geocode(wic_addr,
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.
Out of 59 grocery stores on the AtoZ database, only 26 were found by censusxy, for a return rate of 44%. For the WIC offices, out of 102, censusxy was able to return 85, for a much better rate of 83%.
Now, I combine the grocery and wic addresses using rbind, and create a new category (“TYPE”) to distinguish them:
results<-results %>% mutate(TYPE="Grocery Store")
wic_results<-wic_results %>% mutate(TYPE="WIC Office")
final_results<-rbind(results,wic_results)
Then, I use mapview to look at the final results:
results_map
I am sorry about the weird colors – yellow and purple are not great. I don’t know how to change them. Any advice would be welcome.Also, for some reason mapview doesn’t want to work with Knitr, so I captured a jpg of the map instead.