R Spatial Lab Assignment # 1

Load Files

nyc_zipcodes <- st_read("/Users/alex/Desktop/Data Viz with R/Second Section/Week 7/Section_07/R-Spatial_I_Lab/ZIP_CODE_040114/ZIP_CODE_040114.shp")
## Reading layer `ZIP_CODE_040114' from data source 
##   `/Users/alex/Desktop/Data Viz with R/Second Section/Week 7/Section_07/R-Spatial_I_Lab/ZIP_CODE_040114/ZIP_CODE_040114.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 263 features and 12 fields
## Geometry type: POLYGON
## Dimension:     XY
## Bounding box:  xmin: 913129 ymin: 120020.9 xmax: 1067494 ymax: 272710.9
## Projected CRS: NAD83 / New York Long Island (ftUS)
nys_health_fac <- read.csv("/Users/alex/Desktop/Data Viz with R/Second Section/Week 7/Section_07/NYS_Health_Facility.csv")
nys_retail_food <- read.csv("/Users/alex/Desktop/Data Viz with R/Second Section/Week 7/Section_07/R-Spatial_I_Lab/NYS_Retail_Food_Stores.csv")

Map Zipcodes

mapView(nyc_zipcodes, col.regions="lightblue", label = nyc_zipcodes$ZIPCODE)
nyc_zipcodes %>% dplyr::select(ZIPCODE, PO_NAME, POPULATION, COUNTY) %>%
  mapview::mapview(col.regions="darkgreen", label=nyc_zipcodes$ZIPCODE)

Map Health Facilities

nys_health_fac_na_rm <- nys_health_fac %>% filter(!is.na(Facility.Longitude) & !is.na(Facility.Latitude) & Facility.Latitude > 30)

# filtered out facilities without listed latitude or longitude, and facilities below 30 degrees latitude to get rid of errors

nys_health_sf <- st_as_sf(nys_health_fac_na_rm, coords=c("Facility.Longitude","Facility.Latitude"), crs=4326)

head(nys_health_fac)
##   Facility.ID                                  Facility.Name Short.Description
## 1         204                             Hospice at Lourdes              HSPC
## 2         620        Charles T Sitrin Health Care Center Inc                NH
## 3         654 Central Park Rehabilitation and Nursing Center                NH
## 4        1156                         East Side Nursing Home                NH
## 5        2589                   Wellsville Manor Care Center                NH
## 6        3455              Harris Hill Nursing Facility, LLC                NH
##                              Description Facility.Open.Date
## 1                                Hospice         06/01/1985
## 2 Residential Health Care Facility - SNF         02/01/1989
## 3 Residential Health Care Facility - SNF         02/01/1989
## 4 Residential Health Care Facility - SNF         08/01/1979
## 5 Residential Health Care Facility - SNF         02/01/1989
## 6 Residential Health Care Facility - SNF         04/08/1992
##            Facility.Address.1 Facility.Address.2 Facility.City Facility.State
## 1        4102 Old Vestal Road                           Vestal       New York
## 2          2050 Tilden Avenue                     New Hartford       New York
## 3 116 Martin Luther King East                         Syracuse       New York
## 4              62 Prospect St                           Warsaw       New York
## 5          4192A Bolivar Road                       Wellsville       New York
## 6           2699 Wehrle Drive                    Williamsville       New York
##   Facility.Zip.Code Facility.Phone.Number Facility.Fax.Number Facility.Website
## 1             13850            6077985692                  NA                 
## 2             13413            3157973114                  NA                 
## 3             13205            3154751641                  NA                 
## 4             14569            5857868151                  NA                 
## 5             14895            5855934400                  NA                 
## 6             14221            7166323700                  NA                 
##   Facility.County.Code Facility.County Regional.Office.ID
## 1                    3          Broome                  3
## 2                   32          Oneida                  3
## 3                   33        Onondaga                  3
## 4                   60         Wyoming                  1
## 5                    2        Allegany                  1
## 6                   14            Erie                  1
##                     Regional.Office Main.Site.Name Main.Site.Facility.ID
## 1  Central New York Regional Office                                   NA
## 2  Central New York Regional Office                                   NA
## 3  Central New York Regional Office                                   NA
## 4 Western Regional Office - Buffalo                                   NA
## 5 Western Regional Office - Buffalo                                   NA
## 6 Western Regional Office - Buffalo                                   NA
##   Operating.Certificate.Number                             Operator.Name
## 1                     0301501F Our Lady of Lourdes Memorial Hospital Inc
## 2                     3227304N  Charles T Sitrin Health Care Center, Inc
## 3                     3301326N                                CPRNC, LLC
## 4                     6027303N                East Side Nursing Home Inc
## 5                     0228305N                      Wellsville Manor LLC
## 6                     1406301N         Harris Hill Nursing Facility, LLC
##               Operator.Address.1 Operator.Address.2 Operator.City
## 1            169 Riverside Drive                       Binghamton
## 2         Box 1000 Tilden Avenue                     New Hartford
## 3    116 Martin Luther King East                         Syracuse
## 4             62 Prospect Street                           Warsaw
## 5             4192a Bolivar Road                       Wellsville
## 6 560 Delaware Avenue, Suite 400                          Buffalo
##   Operator.State Operator.Zip.Code Cooperator.Name Cooperator.Address
## 1       New York             13905                                   
## 2       New York             13413                                   
## 3       New York             13205                                   
## 4       New York             14569                                   
## 5       New York             14897                                   
## 6       New York             14202                                   
##   Cooperator.Address.2 Cooperator.City Cooperator.State Cooperator.Zip.Code
## 1                                              New York                  NA
## 2                                              New York                  NA
## 3                                              New York                  NA
## 4                                              New York                  NA
## 5                                              New York                  NA
## 6                                              New York                  NA
##               Ownership.Type Facility.Latitude Facility.Longitude
## 1 Not for Profit Corporation          42.09710          -75.97524
## 2 Not for Profit Corporation          43.05497          -75.22883
## 3                        LLC                NA                 NA
## 4       Business Corporation          42.73898          -78.12867
## 5                        LLC          42.12646          -77.96783
## 6                        LLC          42.95627          -78.68856
##         Facility.Location
## 1 (42.097095, -75.975243)
## 2  (43.05497, -75.228828)
## 3                        
## 4  (42.738979, -78.12867)
## 5 (42.126461, -77.967834)
## 6  (42.956268, -78.68856)
nys_health_sf %>% dplyr::select(Facility.Name, Description, Facility.Address.1, Facility.City, Facility.State) %>% mapview::mapview(label=nys_health_sf$Facility.Name)
# track errors to fix later 
nys_health_errors <- nys_health_fac %>% filter(is.na(Facility.Longitude) | is.na(Facility.Latitude) | Facility.Latitude < 30)

Map Retail Food Locations

head(nys_retail_food)
##   County License.Number Operation.Type Establishment.Type
## 1 Albany         733149          Store             A     
## 2 Albany         704590          Store             JAC   
## 3 Albany         727909          Store             JAC   
## 4 Albany         720557          Store             JAC   
## 5 Albany          15890          Store             A     
## 6 Albany         735254          Store             JAC   
##                         Entity.Name                DBA.Name Street.Number
## 1 SPEEDWAY LLC                      12110                             719
## 2 1250 SELKIRK INC                  1250 SELKIRK                     1250
## 3 RED-KAP SALES INC                 1667 GENERAL STORE               1667
## 4 SAEED SADIQ, SAIKA NOREEN         19 STREET QUICK STOP              315
## 5 AZIZ MOHAMMAD S                   24 HR ALBANY NEWS                   8
## 6 7-ELEVEN INC                      7-ELEVEN                          477
##                       Street.Name Address.Line.2 Address.Line.3
## 1   NEW LOUDON RD                             NA             NA
## 2    RTE 9W & 396                             NA             NA
## 3    WESTERN AVENUE                           NA             NA
## 4   19TH STREET                               NA             NA
## 5 CENTRAL AVE                                 NA             NA
## 6   DELAWARE AVE                              NA             NA
##                 City State Zip.Code Square.Footage
## 1 LATHAM                NY    12110            300
## 2 SELKIRK               NY    12158          3,000
## 3 ALBANY                NY    12203          2,000
## 4 WATERVLIET            NY    12189          1,200
## 5 ALBANY                NY    12210          1,800
## 6 ALBANY                NY    12209              0
##                                                         Location
## 1   719 NEW LOUDON RD\nLATHAM, NY 12110\n(42.739618, -73.761949)
## 2         1250 RTE 9 W\nSELKIRK, NY 12158\n(42.547591, -73.8073)
## 3 1667 WESTERN AVENUE\nALBANY, NY 12203\n(42.686553, -73.854665)
## 4  315 19TH STREET\nWATERVLIET, NY 12189\n(42.73063, -73.703443)
## 5       8 CENTRAL AVE\nALBANY, NY 12210\n(42.657136, -73.763712)
## 6    477 DELAWARE AVE\nALBANY, NY 12209\n(42.639931, -73.784962)
# separate location columns

nys_retail_food <- nys_retail_food %>% separate(Location, into = c("address", "city", "coordinates"), sep="\n", fill="right") %>% mutate(coordinates= gsub("[()]", "", coordinates)) %>% separate(coordinates, into = c("latitude", "longitude"), sep = ",", convert=TRUE)

glimpse(nys_retail_food)
## Rows: 29,389
## Columns: 18
## $ County             <chr> "Albany", "Albany", "Albany", "Albany", "Albany", "…
## $ License.Number     <int> 733149, 704590, 727909, 720557, 15890, 735254, 7088…
## $ Operation.Type     <chr> "Store", "Store", "Store", "Store", "Store", "Store…
## $ Establishment.Type <chr> "A     ", "JAC   ", "JAC   ", "JAC   ", "A     ", "…
## $ Entity.Name        <chr> "SPEEDWAY LLC                     ", "1250 SELKIRK …
## $ DBA.Name           <chr> "12110                  ", "1250 SELKIRK           …
## $ Street.Number      <chr> "719", "1250", "1667", "315", "8", "477", "873", "1…
## $ Street.Name        <chr> "NEW LOUDON RD                ", "RTE 9W & 396     …
## $ Address.Line.2     <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
## $ Address.Line.3     <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
## $ City               <chr> "LATHAM            ", "SELKIRK           ", "ALBANY…
## $ State              <chr> "NY", "NY", "NY", "NY", "NY", "NY", "NY", "NY", "NY…
## $ Zip.Code           <int> 12110, 12158, 12203, 12189, 12210, 12209, 12110, 12…
## $ Square.Footage     <chr> "300", "3,000", "2,000", "1,200", "1,800", "0", "0"…
## $ address            <chr> "719 NEW LOUDON RD", "1250 RTE 9 W", "1667 WESTERN …
## $ city               <chr> "LATHAM, NY 12110", "SELKIRK, NY 12158", "ALBANY, N…
## $ latitude           <dbl> 42.73962, 42.54759, 42.68655, 42.73063, 42.65714, 4…
## $ longitude          <dbl> -73.76195, -73.80730, -73.85466, -73.70344, -73.763…
nys_retail_food_na_rm <- nys_retail_food %>% filter(!is.na(longitude) & !is.na(latitude))

nys_retail_food_sf <- st_as_sf(nys_retail_food_na_rm, coords=c("longitude","latitude"), crs=4326)

nys_retail_food_sf %>% dplyr::select(Entity.Name, City, State, Zip.Code) %>% mapview::mapview(label=nys_retail_food_sf$Entity.Name)