library(tidycensus)
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5     v purrr   0.3.4
## v tibble  3.1.6     v dplyr   1.0.7
## v tidyr   1.1.4     v stringr 1.4.0
## v readr   2.1.1     v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(tmap)
library(dplyr)
library(ggplot2)
library(classInt)
library(patchwork)
library(tmaptools)
library(ggsn)
## Loading required package: grid
library(sysfonts)

Generating an image of map with a legend for both the WIc and grocery store layers:

library(readr)
wic_west_side <- read_csv("C:/Users/shahi/OneDrive - University of Texas at San Antonio/Desktop/Spring'22/Dem 5093 (GIS)/wic_west_side.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...
## 
## i Use `spec()` to retrieve the full column specification for this data.
## i Specify the column types or set `show_col_types = FALSE` to quiet this message.
wic_west_side<- wic_west_side[c(6,12:14)]
names(wic_west_side)<-c("street","city","st","zip")
head(wic_west_side)
## # A tibble: 6 x 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)
results<-cxy_geocode(wic_west_side,
                     street="street",
                     city="city",
                     state="st",
                     zip="zip",
                     class="sf",
                     output="simple")
## 25 rows removed to create an sf object. These were addresses that the geocoder could not match.

Basic interactive map of the points:

library(mapview)
mapview(results,layer.name="WIC Services")

Saving the result to a shapefile:

library(sf)
## Linking to GEOS 3.9.1, GDAL 3.2.1, PROJ 7.2.1; sf_use_s2() is TRUE
st_write(results,dsn="C:/Users/shahi/OneDrive - University of Texas at San Antonio/Desktop/Spring'22/Dem 5093 (GIS)/gis_classwork",layer="westside_wic", driver= "ESRI Shapefile",delete_layer =T, append=T)
## Deleting layer `westside_wic' using driver `ESRI Shapefile'
## Updating layer `westside_wic' to data source `C:/Users/shahi/OneDrive - University of Texas at San Antonio/Desktop/Spring'22/Dem 5093 (GIS)/gis_classwork' using driver `ESRI Shapefile'
## Writing 77 features with 4 fields and geometry type Point.

Results:

## [1] 102
## [1] 77

Percentage correctly geo-coded

## [1] 75.5

Repeating the process for Grocery Stores of West side of San Antonio:

library(readr)
grocery_west_side <- read_csv("C:/Users/shahi/OneDrive - University of Texas at San Antonio/Desktop/Spring'22/Dem 5093 (GIS)/grocery_west_side.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...
## 
## i Use `spec()` to retrieve the full column specification for this data.
## i Specify the column types or set `show_col_types = FALSE` to quiet this message.
grocery_west_side<- grocery_west_side[c(6,12:14)]
names(grocery_west_side)<-c("street","city","st","zip")
head(grocery_west_side)
## # A tibble: 6 x 4
##   street                 city        st      zip
##   <chr>                  <chr>       <chr> <dbl>
## 1 1314 Fredericksburg Rd San Antonio TX    78201
## 2 1545 S San Marcos      San Antonio TX    78207
## 3 4522 Fredericksburg Rd San Antonio TX    78201
## 4 111 S Leona St         San Antonio TX    78207
## 5 3485 Fredericksburg Rd San Antonio TX    78201
## 6 1502 W Hildebrand Ave  San Antonio TX    78201
library(censusxy)
results1<-cxy_geocode(grocery_west_side,
                     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.
library(mapview)
mapview(results1,layer.name="Grocery Stores")
library(sf)

st_write(results1,dsn="C:/Users/shahi/OneDrive - University of Texas at San Antonio/Desktop/Spring'22/Dem 5093 (GIS)/gis_classwork",layer="westside_grocery", driver= "ESRI Shapefile",delete_layer =T, append=T)
## Deleting layer `westside_grocery' using driver `ESRI Shapefile'
## Updating layer `westside_grocery' to data source `C:/Users/shahi/OneDrive - University of Texas at San Antonio/Desktop/Spring'22/Dem 5093 (GIS)/gis_classwork' using driver `ESRI Shapefile'
## Writing 31 features with 4 fields and geometry type Point.

Results:

## [1] 58
## [1] 31

Percentage correctly geo-coded

## [1] 53.4