##load libraries
library(censusxy)
library(readr)
library(data.table)Homework 4
The echo: false option disables the printing of code (only output is displayed).
MAPPING WIC STORES
##LOADING WIC STORE DATA
wicstores <- read_csv("C:/Users/okabe/OneDrive/Pictures/Stats 2/GIS/wic_west_side.csv")New names:
Rows: 103 Columns: 227
── Column specification
──────────────────────────────────────────────────────── Delimiter: "," chr
(113): Source...1, Date, Obsolescence Date, Business Name, Legal Name, P... dbl
(42): Physical Address Number, Physical ZIP, Physical ZIP 4, Mailing Ad... lgl
(70): 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.
• `Source` -> `Source...1`
• `Source` -> `Source...227`
head(wicstores)# A tibble: 6 × 227
Source…¹ Date Obsol…² Busin…³ Legal…⁴ Physi…⁵ Physi…⁶ Physi…⁷ Physi…⁸ Physi…⁹
<chr> <chr> <chr> <chr> <chr> <chr> <dbl> <chr> <chr> <chr>
1 AtoZDat… 2/23… 8/23/2… Coalit… <NA> 1013 S… 1013 S San Ja… St
2 AtoZDat… 2/23… 8/23/2… San An… <NA> 1102 D… 1102 <NA> Delgado St
3 AtoZDat… 2/23… 8/23/2… Center… <NA> 1115 W… 1115 W Martin St
4 AtoZDat… 2/23… 8/23/2… Profes… <NA> 1115 W… 1115 W Martin St
5 AtoZDat… 2/23… 8/23/2… Linda … <NA> 1115 W… 1115 W Martin St
6 AtoZDat… 2/23… 8/23/2… Adrian… Center… 1115 W… 1115 W Martin St
# … with 217 more variables: `Physical Post Direction` <lgl>,
# `Physical City` <chr>, `Physical State` <chr>, `Physical ZIP` <dbl>,
# `Physical ZIP 4` <dbl>, `Key Executive Name` <chr>, `First Name` <chr>,
# `Middle Initial` <chr>, `Last Name` <chr>, Title <chr>, Gender <chr>,
# `Location Employee Size` <dbl>, `Corporate Employee Size` <dbl>,
# `Revenue / Yr` <chr>, `Mailing Address` <chr>,
# `Mailing Address Number` <dbl>, `Mailing Pre Direction` <chr>, …
wic<-wicstores[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 1013 S San Jacinto St San Antonio TX 78207
2 1102 Delgado St San Antonio TX 78207
3 1115 W Martin St San Antonio TX 78207
4 1115 W Martin St San Antonio TX 78207
5 1115 W Martin St San Antonio TX 78207
6 1115 W Martin St San Antonio TX 78207
library(censusxy)
wicresults<-cxy_geocode(wic,
street = "street",
city = "city",
state ="st",
zip = "zip",
class="sf",
output = "simple")5 rows removed to create an sf object. These were addresses that the geocoder could not match.
Basic interactive maps of the points for WIC Service stores
Lydia Okabe
Source: https://www-atozdatabases-com.libweb.lib.utsa.edu/usbusiness/result
library(mapview)
mapview(wicresults, layer.name="WIC Services",col.regions = "green")WIC Stores Longitude and Latitude
library(sf)Linking to GEOS 3.9.1, GDAL 3.4.3, PROJ 7.2.1; sf_use_s2() is TRUE
library(dplyr)
Attaching package: 'dplyr'
The following objects are masked from 'package:data.table':
between, first, last
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
addrLL<-read.csv ("C:/Users/okabe/OneDrive/Pictures/Stats 2/GIS/wic_west_side.csv")
resultsWIC <- st_as_sf(addrLL, coords=c("Longitude", "Latitude"), crs=4269,agr="constant")
resultsWIC.proj<-st_transform(resultsWIC,
crs = 2278)WIC Stores Longitude and Latitude map
Lydia Okabe
Source: https://www-atozdatabases-com.libweb.lib.utsa.edu/usbusiness/result
mapview(resultsWIC.proj,col.regions = "darkgreen")MAPPING GROCERY STORES
##load data for grocery stores
grocerystores <- read_csv("C:/Users/okabe/OneDrive/Pictures/Stats 2/GIS/grocery_stores.csv")New names:
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.
• `Source` -> `Source...1`
• `Source` -> `Source...227`
• `` -> `...228`
head(grocerystores)# A tibble: 6 × 228
Source…¹ Date Obsol…² Busin…³ Legal…⁴ Physi…⁵ Physi…⁶ Physi…⁷ Physi…⁸ Physi…⁹
<chr> <chr> <chr> <chr> <chr> <chr> <dbl> <chr> <chr> <chr>
1 AtoZDat… 02/2… 08/23/… Surlea… <NA> 1545 S… 1545 S San Ma… <NA>
2 AtoZDat… 02/2… 08/23/… Super … <NA> 4522 F… 4522 <NA> Freder… Rd
3 AtoZDat… 02/2… 08/23/… Pico D… <NA> 111 S … 111 S Leona St
4 AtoZDat… 02/2… 08/23/… Target Target… 4522 F… 4522 <NA> Freder… Rd
5 AtoZDat… 02/2… 08/23/… H-E-B … <NA> 3485 F… 3485 <NA> Freder… Rd
6 AtoZDat… 02/2… 08/23/… Balcon… <NA> 3309 H… 3309 <NA> Hillcr… Dr
# … with 218 more variables: `Physical Post Direction` <lgl>,
# `Physical City` <chr>, `Physical State` <chr>, `Physical ZIP` <dbl>,
# `Physical ZIP 4` <dbl>, `Key Executive Name` <chr>, `First Name` <chr>,
# `Middle Initial` <chr>, `Last Name` <chr>, Title <chr>, Gender <chr>,
# `Location Employee Size` <dbl>, `Corporate Employee Size` <dbl>,
# `Revenue / Yr` <chr>, `Mailing Address` <chr>,
# `Mailing Address Number` <dbl>, `Mailing Pre Direction` <chr>, …
grocery<-grocerystores[c(4,6, 12:14)]
names(grocery)<-c("business name","street", "city", "st", "zip" )
head(grocery)# A tibble: 6 × 5
`business name` street city st zip
<chr> <chr> <chr> <chr> <dbl>
1 Surlean Foods 1545 S San Marcos San Antonio TX 78207
2 Super Target 4522 Fredericksburg Rd San Antonio TX 78201
3 Pico De Gallo 111 S Leona St San Antonio TX 78207
4 Target 4522 Fredericksburg Rd San Antonio TX 78201
5 H-E-B LP 3485 Fredericksburg Rd San Antonio TX 78201
6 Balcones Food Store 3309 Hillcrest Dr San Antonio TX 78201
library(censusxy)
results<-cxy_geocode(grocery,
street = "street",
city = "city",
state ="st",
zip = "zip",
class="sf",
output = "simple")4 rows removed to create an sf object. These were addresses that the geocoder could not match.
Basic interactive map of the points for grocery stores in West side San Antonio
Lydia Okabe
Source: https://www-atozdatabases-com.libweb.lib.utsa.edu/usbusiness/result
###basic map
library(mapview)
mapview(results, layer.name="Grocery Stores",col.regions = "purple")##longitude and latitude for grocery stores
library(sf)
library(dplyr)
addrLL<-read.csv("C:/Users/okabe/OneDrive/Pictures/Stats 2/GIS/grocery_stores.csv")
resultsgrocery <- st_as_sf(addrLL, coords=c("Longitude", "Latitude"), crs=4269,agr="constant")
resultsgrocery.proj<-st_transform(resultsgrocery,
crs = 2278)Longitude and latitude interactive map of the points for grocery stores in West side San Antonio
Lydia Okabe
Source: https://www-atozdatabases-com.libweb.lib.utsa.edu/usbusiness/result
mapview(resultsgrocery.proj)Extra credit
Interactive map of the points for grocery stores in West side San Antonio with all four elements
Lydia Okabe
Source: https://www-atozdatabases-com.libweb.lib.utsa.edu/usbusiness/result
mapview(list(wicresults, resultsWIC.proj,results,resultsgrocery.proj),
layer.name = c("WIC Locations", "WIC LL", "Grocery Stores", "Grocery StoresLL"), col.regions=list("blue","black", "green", "brown"),col=list("blue","black", "green", "brown"))