This is my submission for Week 07
library(sf)
library(sp)
library(rgdal)
library(raster)
library(rgeos)
library(dplyr)
library(tidyverse)
library(classInt)
library(RColorBrewer)
library(ggplot2)
library(ggmap)
library(tmap)
library(mapview)
library(leaflet)
#load in the zip code data
nyc_zip <- st_read(file.path(data_dir, "R-Spatial_I_Lab/ZIP_CODE_040114/ZIP_CODE_040114.shp"))
plot(st_geometry(nyc_zip), main='Pure geometry with st_geometry function')
#load in the health data
healthfact <- read_csv(file.path(data_dir,"R-Spatial_I_Lab/NYS_Health_Facility.csv"),show_col_types = FALSE)
str(healthfact)
healthfact <- healthfact[!is.na(healthfact$`Facility Longitude`) & !is.na(healthfact$`Facility Latitude`), ]
health_sf <- st_as_sf(healthfact, coords = c("Facility Longitude", "Facility Latitude"))
#load in the retail data
retail <- read_csv(file.path(data_dir,"R-Spatial_I_Lab/nys_retail_food_store_xy.csv"),show_col_types = FALSE)
retail_new <- st_as_sf(retail, coords = c("X", "Y"), crs = 4326)
plot(st_geometry(retail_new), main='Pure geometry with st_geometry function')
#plot all three
zip_layer <- mapview(nyc_zip, color = "gray", alpha.regions = 0.3)
health_layer <- mapview(health_sf, color = "red")
retail_layer <- mapview(retail_new, color = "blue")
#combine layers
zip_layer + health_layer + retail_layer
#save to file
save(nyc_zip, health_sf, retail_new, file = "C:/Users/erins/OneDrive - SOHO SOLUTIONS INC/Documents/assignment_4/Week_07/spatial_data.RData")
load("spatial_data.RData")
# Save all three sf objects to a single GeoPackage file
st_write(nyc_zip, "spatial_data.gpkg", layer = "nyc_zip", delete_layer = TRUE)
st_write(health_sf, "spatial_data.gpkg", layer = "health_sf", delete_layer = TRUE)
st_write(retail_new, "spatial_data.gpkg", layer = "retail_new", delete_layer = TRUE)