Packages

library(censusxy)
## Warning: package 'censusxy' was built under R version 4.0.4
library(tmap)
library(sf)
library(tidyverse)
library(readxl)

Read in Data

wic <- read_excel("Data/wic_west_side.xls")
## New names:
## * Source -> Source...1
## * Source -> Source...223
grocery <- read_excel("Data/grocery_west_side.xls")
## New names:
## * Source -> Source...1
## * Source -> Source...223

#Selecting Address

addvar <- c("Business Name","Physical Address", "Physical City", "Physical State", "Physical ZIP")

wicadd<- wic %>% 
  select(addvar)
## Note: Using an external vector in selections is ambiguous.
## i Use `all_of(addvar)` instead of `addvar` to silence this message.
## i See <https://tidyselect.r-lib.org/reference/faq-external-vector.html>.
## This message is displayed once per session.
groceryadd <- grocery %>% 
  select(addvar)

Geocoding

wicgeo <- cxy_geocode(wicadd,
                      street = "Physical Address",
                      city = "Physical City",
                      state = "Physical State",
                      zip = "Physical ZIP",
                      class="sf",
                      output = "simple")
## 18 rows removed to create an sf object. These were addresses that the geocoder could not match.
grocerygeo <- cxy_geocode(groceryadd,
                      street = "Physical Address",
                      city = "Physical City",
                      state = "Physical State",
                      zip = "Physical ZIP",
                      class="sf",
                      output = "simple")
## 16 rows removed to create an sf object. These were addresses that the geocoder could not match.

How well did we geocode

str_c("WIC ",round(nrow(wicgeo)/nrow(wicadd) * 100), "% match")
## [1] "WIC 82% match"
str_c("Grocery ",round(nrow(grocerygeo)/nrow(groceryadd) *100),"% match")
## [1] "Grocery 73% match"

Mapping coordinates

#making Dummy variables for legend
wicgeo$Legend <-  "WIC Places"
grocerygeo$Legend <- "Grocery Stores"

totalmap <- rbind(wicgeo,grocerygeo) #Merging data to mape in one tm_shape
tmap_mode("view")
## tmap mode set to interactive viewing
tm_shape(totalmap, title = "WIC Places") +
  tm_dots(col = "Legend")