Author

Alijah Anyagwosi

Published

March 22, 2025

Explanation of the template

Update the title with your information. Make sure to include identification information so that we know it is your submission.

Also update the author name and date accordingly.

Check out the Source Code from the top-right corner </>Code menu.

In the following R code chunk, load_packages is the code chunk name. include=FALSE suggests that the code chunk will run, but the code itself and its outputs will not be included in the rendered HTML. echo=TRUE in the following code chunk suggests that the code and results from running the code will be included in the rendered HTML.

R Spatial Lab Assignment # 1

Don’t use a single chunk for the entire assignment. Break it into multiple chunks.

You can name the code chunk and also set options.

Example:

Show the code
require(tidyverse)
require(sf)

b<-8/4
print(b)
[1] 2

task 1:

Show the code
smpCode <- "hello, R markdown and RPubs!"

cat(smpCode)
hello, R markdown and RPubs!

task 2:

Quarto markdown is different from R markdown in terms of chunk options. See chunk options at Quarto website.

Show the code
print("This is the new code chunk options available in Quarto Markdown")
[1] "This is the new code chunk options available in Quarto Markdown"

Assignment Part 1.

Show the code
unzip("R-Spatial_I_Lab.zip", exdir = "data_RS_WEEK_7")

list.of.packages <- c("sf", "sp", "spatial", "maptools", "rgeos","rgdal",
                      "raster", "grid", "rasterVis",
                      "tidyverse", "magrittr", "ggpubr", "lubridate",
                      "devtools", "htmlwidgets", "mapview",
                      "classInt", "RColorBrewer", "ggmap", "tmap", "leaflet", "mapview", 
                      "ggrepel", "ggsn",
                      "spdep","spatialreg","GWmodel");
Show the code
# Unzip the inner zip file
unzip("data_RS_WEEK_7/ZIP_CODE_040114.zip", exdir = "data_RS_WEEK_7/NewZIP")
Show the code
nyc_sf_ZIP <- st_read("data_RS_WEEK_7/NewZIP/ZIP_CODE_040114.shp")
Reading layer `ZIP_CODE_040114' from data source 
  `C:\Users\Alijah Anyagwosi\Downloads\SPRING 2025\RStudio\data_RS_WEEK_7\NewZIP\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)
Show the code
str(nyc_sf_ZIP)
Classes 'sf' and 'data.frame':  263 obs. of  13 variables:
 $ ZIPCODE   : chr  "11436" "11213" "11212" "11225" ...
 $ BLDGZIP   : chr  "0" "0" "0" "0" ...
 $ PO_NAME   : chr  "Jamaica" "Brooklyn" "Brooklyn" "Brooklyn" ...
 $ POPULATION: num  18681 62426 83866 56527 72280 ...
 $ AREA      : num  22699295 29631004 41972104 23698630 36868799 ...
 $ STATE     : chr  "NY" "NY" "NY" "NY" ...
 $ COUNTY    : chr  "Queens" "Kings" "Kings" "Kings" ...
 $ ST_FIPS   : chr  "36" "36" "36" "36" ...
 $ CTY_FIPS  : chr  "081" "047" "047" "047" ...
 $ URL       : chr  "http://www.usps.com/" "http://www.usps.com/" "http://www.usps.com/" "http://www.usps.com/" ...
 $ SHAPE_AREA: num  0 0 0 0 0 0 0 0 0 0 ...
 $ SHAPE_LEN : num  0 0 0 0 0 0 0 0 0 0 ...
 $ geometry  :sfc_POLYGON of length 263; first list element: List of 1
  ..$ : num [1:159, 1:2] 1038098 1038142 1038171 1038280 1038521 ...
  ..- attr(*, "class")= chr [1:3] "XY" "POLYGON" "sfg"
 - attr(*, "sf_column")= chr "geometry"
 - attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA NA NA NA NA NA ...
  ..- attr(*, "names")= chr [1:12] "ZIPCODE" "BLDGZIP" "PO_NAME" "POPULATION" ...
Show the code
plot(st_geometry(nyc_sf_ZIP), main='Pure geometry with st_geometry function')

Show the code
# Load NYS Health Facility Data
health_data <- read.csv("data_RS_WEEK_7/NYS_Health_Facility.csv")

#rfs_xy_data <- read.csv("data_RS_WEEK_7/nys_retail_food_store_xy.csv")

rfs_data <- read.csv("data_RS_WEEK_7/NYS_Retail_Food_Stores.csv")
Show the code
plot(nyc_sf_ZIP['PO_NAME'], main='One column with ["PO_NAME"]')

Show the code
# Two columns, with geometry
plot(nyc_sf_ZIP[c('PO_NAME', 'POPULATION')], main='Two Columns with ["PO_NAME", "POPULATION"]')

Show the code
# 
nyc_sf_HighPOP <- nyc_sf_ZIP[nyc_sf_ZIP$POPULATION > 100000, ]
plot(st_geometry(nyc_sf_ZIP))
plot(st_geometry(nyc_sf_HighPOP), add=T, col="blue")

Show the code
#
nyc_sf_LowPOP <- nyc_sf_ZIP[nyc_sf_ZIP$POPULATION < 5000, ]
plot(st_geometry(nyc_sf_ZIP))
plot(st_geometry(nyc_sf_LowPOP), add=T, col="red")

Show the code
plot(nyc_sf_ZIP %>% st_geometry(), col = 'NA', bg= "black", border='white', lwd=0.5)

nyc_sf_ZIP %>% 
  filter(POPULATION > 100000) %>% 
  st_geometry() %>% 
  plot(col="yellow", add=T)

Show the code
# We use all the default options, but select a few columns. 
# If we use all columns, the popup window will be too big. 
nyc_sf_ZIP %>% dplyr::select(PO_NAME, ZIPCODE, POPULATION) %>%
  mapview::mapview()
Show the code
nyc_sf_ZIP <- st_transform(nyc_sf_ZIP, crs = 4326)
Show the code
nyc_sf_ZIP %>% dplyr::select(PO_NAME, ZIPCODE, POPULATION, AREA) -> tmp_sf_ZIP

mapview(tmp_sf_ZIP, zcol='PO_NAME', layer.name = 'Neighborhood or Borough', stroke=FALSE) + 
  mapview(nyc_sf_ZIP, zcol='POPULATION', 
          layer.name = 'Total Population', 
          homebutton=FALSE, 
          legend=FALSE,
          hide = TRUE,
          label="Population",
          popup = 'Population') +
  mapview(nyc_sf_ZIP, zcol="AREA", 
          layer.name = 'Area of the Zipcode', 
          homebutton=FALSE, 
          legend=FALSE,
          hide=TRUE,
          label="Land Area",
          popup = 'Land Area')
Show the code
# This variable has one layer
tmpMapObj_1 <- mapView(tmp_sf_ZIP, zcol='PO_NAME', layer.name = 'Neighborhood or Borough', stroke=FALSE)

# This is another layer
tmpMapObj_2 <- mapView(x = tmp_sf_ZIP, zcol='POPULATION', 
          layer.name = 'Total Population', 
          homebutton=FALSE, 
          legend=FALSE,
          hide = TRUE) 

# We can add a new layer to an existing layer
tmpMapObj_3 <- tmpMapObj_1 + mapView(x = tmp_sf_ZIP, zcol="AREA", 
          layer.name = 'Population with Doctorate', 
          homebutton=FALSE, 
          legend=FALSE,
          hide=TRUE,
          label="Land Area",
          popup = 'Land Area')

# This show three layers
tmpMapObj_2 + tmpMapObj_3
Show the code
NYS_health_data <- read.csv("data_RS_WEEK_7/NYS_Health_Facility.csv")

NYS_health_data_new <- NYS_health_data %>%
  filter(!is.na(Facility.Longitude) & !is.na(Facility.Latitude))

NYS_health_fac_sf <- st_as_sf(NYS_health_data_new, 
                          coords = c("Facility.Longitude", "Facility.Latitude"), 
                          crs = 4326)
Show the code
str(NYS_health_fac_sf)
Classes 'sf' and 'data.frame':  3848 obs. of  35 variables:
 $ Facility.ID                 : int  204 620 1156 2589 3455 3853 4249 4473 6230 6482 ...
 $ Facility.Name               : chr  "Hospice at Lourdes" "Charles T Sitrin Health Care Center Inc" "East Side Nursing Home" "Wellsville Manor Care Center" ...
 $ Short.Description           : chr  "HSPC" "NH" "NH" "NH" ...
 $ Description                 : chr  "Hospice" "Residential Health Care Facility - SNF" "Residential Health Care Facility - SNF" "Residential Health Care Facility - SNF" ...
 $ Facility.Open.Date          : chr  "06/01/1985" "02/01/1989" "08/01/1979" "02/01/1989" ...
 $ Facility.Address.1          : chr  "4102 Old Vestal Road" "2050 Tilden Avenue" "62 Prospect St" "4192A Bolivar Road" ...
 $ Facility.Address.2          : chr  "" "" "" "" ...
 $ Facility.City               : chr  "Vestal" "New Hartford" "Warsaw" "Wellsville" ...
 $ Facility.State              : chr  "New York" "New York" "New York" "New York" ...
 $ Facility.Zip.Code           : chr  "13850" "13413" "14569" "14895" ...
 $ Facility.Phone.Number       : num  6.08e+09 3.16e+09 5.86e+09 5.86e+09 7.17e+09 ...
 $ Facility.Fax.Number         : num  NA NA NA NA NA ...
 $ Facility.Website            : chr  "" "" "" "" ...
 $ Facility.County.Code        : int  3 32 60 2 14 29 14 29 7093 29 ...
 $ Facility.County             : chr  "Broome" "Oneida" "Wyoming" "Allegany" ...
 $ Regional.Office.ID          : int  3 3 1 1 1 7 1 7 5 7 ...
 $ Regional.Office             : chr  "Central New York Regional Office" "Central New York Regional Office" "Western Regional Office - Buffalo" "Western Regional Office - Buffalo" ...
 $ Main.Site.Name              : chr  "" "" "" "" ...
 $ Main.Site.Facility.ID       : int  NA NA NA NA NA NA NA NA 1463 NA ...
 $ Operating.Certificate.Number: chr  "0301501F" "3227304N" "6027303N" "0228305N" ...
 $ Operator.Name               : chr  "Our Lady of Lourdes Memorial Hospital Inc" "Charles T Sitrin Health Care Center, Inc" "East Side Nursing Home Inc" "Wellsville Manor LLC" ...
 $ Operator.Address.1          : chr  "169 Riverside Drive" "Box 1000 Tilden Avenue" "62 Prospect Street" "4192a Bolivar Road" ...
 $ Operator.Address.2          : chr  "" "" "" "" ...
 $ Operator.City               : chr  "Binghamton" "New Hartford" "Warsaw" "Wellsville" ...
 $ Operator.State              : chr  "New York" "New York" "New York" "New York" ...
 $ Operator.Zip.Code           : chr  "13905" "13413" "14569" "14897" ...
 $ Cooperator.Name             : chr  "" "" "" "" ...
 $ Cooperator.Address          : chr  "" "" "" "" ...
 $ Cooperator.Address.2        : chr  "" "" "" "" ...
 $ Cooperator.City             : chr  "" "" "" "" ...
 $ Cooperator.State            : chr  "New York" "New York" "New York" "New York" ...
 $ Cooperator.Zip.Code         : int  NA NA NA NA NA NA NA NA NA NA ...
 $ Ownership.Type              : chr  "Not for Profit Corporation" "Not for Profit Corporation" "Business Corporation" "LLC" ...
 $ Facility.Location           : chr  "(42.097095, -75.975243)" "(43.05497, -75.228828)" "(42.738979, -78.12867)" "(42.126461, -77.967834)" ...
 $ geometry                    :sfc_POINT of length 3848; first list element:  'XY' num  -76 42.1
 - attr(*, "sf_column")= chr "geometry"
 - attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA NA NA NA NA NA ...
  ..- attr(*, "names")= chr [1:34] "Facility.ID" "Facility.Name" "Short.Description" "Description" ...
Show the code
NYS_health_sf <- st_as_sf(NYS_health_fac_sf, 
                               coords = c("Longitude", "Latitude")) 
Show the code
str(NYS_health_sf)
Classes 'sf' and 'data.frame':  3848 obs. of  35 variables:
 $ Facility.ID                 : int  204 620 1156 2589 3455 3853 4249 4473 6230 6482 ...
 $ Facility.Name               : chr  "Hospice at Lourdes" "Charles T Sitrin Health Care Center Inc" "East Side Nursing Home" "Wellsville Manor Care Center" ...
 $ Short.Description           : chr  "HSPC" "NH" "NH" "NH" ...
 $ Description                 : chr  "Hospice" "Residential Health Care Facility - SNF" "Residential Health Care Facility - SNF" "Residential Health Care Facility - SNF" ...
 $ Facility.Open.Date          : chr  "06/01/1985" "02/01/1989" "08/01/1979" "02/01/1989" ...
 $ Facility.Address.1          : chr  "4102 Old Vestal Road" "2050 Tilden Avenue" "62 Prospect St" "4192A Bolivar Road" ...
 $ Facility.Address.2          : chr  "" "" "" "" ...
 $ Facility.City               : chr  "Vestal" "New Hartford" "Warsaw" "Wellsville" ...
 $ Facility.State              : chr  "New York" "New York" "New York" "New York" ...
 $ Facility.Zip.Code           : chr  "13850" "13413" "14569" "14895" ...
 $ Facility.Phone.Number       : num  6.08e+09 3.16e+09 5.86e+09 5.86e+09 7.17e+09 ...
 $ Facility.Fax.Number         : num  NA NA NA NA NA ...
 $ Facility.Website            : chr  "" "" "" "" ...
 $ Facility.County.Code        : int  3 32 60 2 14 29 14 29 7093 29 ...
 $ Facility.County             : chr  "Broome" "Oneida" "Wyoming" "Allegany" ...
 $ Regional.Office.ID          : int  3 3 1 1 1 7 1 7 5 7 ...
 $ Regional.Office             : chr  "Central New York Regional Office" "Central New York Regional Office" "Western Regional Office - Buffalo" "Western Regional Office - Buffalo" ...
 $ Main.Site.Name              : chr  "" "" "" "" ...
 $ Main.Site.Facility.ID       : int  NA NA NA NA NA NA NA NA 1463 NA ...
 $ Operating.Certificate.Number: chr  "0301501F" "3227304N" "6027303N" "0228305N" ...
 $ Operator.Name               : chr  "Our Lady of Lourdes Memorial Hospital Inc" "Charles T Sitrin Health Care Center, Inc" "East Side Nursing Home Inc" "Wellsville Manor LLC" ...
 $ Operator.Address.1          : chr  "169 Riverside Drive" "Box 1000 Tilden Avenue" "62 Prospect Street" "4192a Bolivar Road" ...
 $ Operator.Address.2          : chr  "" "" "" "" ...
 $ Operator.City               : chr  "Binghamton" "New Hartford" "Warsaw" "Wellsville" ...
 $ Operator.State              : chr  "New York" "New York" "New York" "New York" ...
 $ Operator.Zip.Code           : chr  "13905" "13413" "14569" "14897" ...
 $ Cooperator.Name             : chr  "" "" "" "" ...
 $ Cooperator.Address          : chr  "" "" "" "" ...
 $ Cooperator.Address.2        : chr  "" "" "" "" ...
 $ Cooperator.City             : chr  "" "" "" "" ...
 $ Cooperator.State            : chr  "New York" "New York" "New York" "New York" ...
 $ Cooperator.Zip.Code         : int  NA NA NA NA NA NA NA NA NA NA ...
 $ Ownership.Type              : chr  "Not for Profit Corporation" "Not for Profit Corporation" "Business Corporation" "LLC" ...
 $ Facility.Location           : chr  "(42.097095, -75.975243)" "(43.05497, -75.228828)" "(42.738979, -78.12867)" "(42.126461, -77.967834)" ...
 $ geometry                    :sfc_POINT of length 3848; first list element:  'XY' num  -76 42.1
 - attr(*, "sf_column")= chr "geometry"
 - attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA NA NA NA NA NA ...
  ..- attr(*, "names")= chr [1:34] "Facility.ID" "Facility.Name" "Short.Description" "Description" ...
Show the code
st_crs(NYS_health_sf) <- 4326

st_crs(NYS_health_sf)
Coordinate Reference System:
  User input: EPSG:4326 
  wkt:
GEOGCRS["WGS 84",
    ENSEMBLE["World Geodetic System 1984 ensemble",
        MEMBER["World Geodetic System 1984 (Transit)"],
        MEMBER["World Geodetic System 1984 (G730)"],
        MEMBER["World Geodetic System 1984 (G873)"],
        MEMBER["World Geodetic System 1984 (G1150)"],
        MEMBER["World Geodetic System 1984 (G1674)"],
        MEMBER["World Geodetic System 1984 (G1762)"],
        MEMBER["World Geodetic System 1984 (G2139)"],
        MEMBER["World Geodetic System 1984 (G2296)"],
        ELLIPSOID["WGS 84",6378137,298.257223563,
            LENGTHUNIT["metre",1]],
        ENSEMBLEACCURACY[2.0]],
    PRIMEM["Greenwich",0,
        ANGLEUNIT["degree",0.0174532925199433]],
    CS[ellipsoidal,2],
        AXIS["geodetic latitude (Lat)",north,
            ORDER[1],
            ANGLEUNIT["degree",0.0174532925199433]],
        AXIS["geodetic longitude (Lon)",east,
            ORDER[2],
            ANGLEUNIT["degree",0.0174532925199433]],
    USAGE[
        SCOPE["Horizontal component of 3D system."],
        AREA["World."],
        BBOX[-90,-180,90,180]],
    ID["EPSG",4326]]
Show the code
NYS_health_sf
Simple feature collection with 3848 features and 34 fields
Geometry type: POINT
Dimension:     XY
Bounding box:  xmin: -79.6299 ymin: -75.45935 xmax: 43.21162 ymax: 44.97849
Geodetic CRS:  WGS 84
First 10 features:
   Facility.ID                           Facility.Name Short.Description
1          204                      Hospice at Lourdes              HSPC
2          620 Charles T Sitrin Health Care Center Inc                NH
3         1156                  East Side Nursing Home                NH
4         2589            Wellsville Manor Care Center                NH
5         3455       Harris Hill Nursing Facility, LLC                NH
6         3853                Garden City Surgi Center               DTC
7         4249                                Willcare              CHHA
8         4473                   Good Shepherd Hospice              HSPC
9         6230                  NYU Langone Rutherford           HOSP-EC
10        6482    Endoscopy Center of Long Island, LLC               DTC
                              Description Facility.Open.Date
1                                 Hospice         06/01/1985
2  Residential Health Care Facility - SNF         02/01/1989
3  Residential Health Care Facility - SNF         08/01/1979
4  Residential Health Care Facility - SNF         02/01/1989
5  Residential Health Care Facility - SNF         04/08/1992
6         Diagnostic and Treatment Center         04/07/2008
7            Certified Home Health Agency         05/15/1990
8                                 Hospice         09/01/2002
9               Hospital Extension Clinic         01/01/2006
10        Diagnostic and Treatment Center         01/20/2003
                   Facility.Address.1 Facility.Address.2 Facility.City
1                4102 Old Vestal Road                           Vestal
2                  2050 Tilden Avenue                     New Hartford
3                      62 Prospect St                           Warsaw
4                  4192A Bolivar Road                       Wellsville
5                   2699 Wehrle Drive                    Williamsville
6                       400 Endo Blvd                      Garden City
7                 346 Delaware Avenue                          Buffalo
8  110 Bi-County Boulevard, Suite 114                      Farmingdale
9                      305 Second Ave                         New York
10                 711 Stewart Avenue                      Garden City
   Facility.State Facility.Zip.Code Facility.Phone.Number Facility.Fax.Number
1        New York             13850            6077985692                  NA
2        New York             13413            3157973114                  NA
3        New York             14569            5857868151                  NA
4        New York             14895            5855934400                  NA
5        New York             14221            7166323700                  NA
6        New York             11530            5168328504                  NA
7        New York             14202            7168567500                  NA
8        New York             11735            6314656300          6314656533
9        New York             10003            2125986570                  NA
10       New York             11530            5162273254                  NA
   Facility.Website Facility.County.Code Facility.County Regional.Office.ID
1                                      3          Broome                  3
2                                     32          Oneida                  3
3                                     60         Wyoming                  1
4                                      2        Allegany                  1
5                                     14            Erie                  1
6                                     29          Nassau                  7
7                                     14            Erie                  1
8                                     29          Nassau                  7
9                                   7093        New York                  5
10                                    29          Nassau                  7
                                     Regional.Office        Main.Site.Name
1                   Central New York Regional Office                      
2                   Central New York Regional Office                      
3                  Western Regional Office - Buffalo                      
4                  Western Regional Office - Buffalo                      
5                  Western Regional Office - Buffalo                      
6    Metropolitan Area Regional Office - Long Island                      
7                  Western Regional Office - Buffalo                      
8    Metropolitan Area Regional Office - Long Island                      
9  Metropolitan Area Regional Office - New York City NYU Langone Hospitals
10   Metropolitan Area Regional Office - Long Island                      
   Main.Site.Facility.ID Operating.Certificate.Number
1                     NA                     0301501F
2                     NA                     3227304N
3                     NA                     6027303N
4                     NA                     0228305N
5                     NA                     1406301N
6                     NA                     2905204R
7                     NA                      1401606
8                     NA                     5151501F
9                   1463                     7002053H
10                    NA                     2905202R
                               Operator.Name             Operator.Address.1
1  Our Lady of Lourdes Memorial Hospital Inc            169 Riverside Drive
2   Charles T Sitrin Health Care Center, Inc         Box 1000 Tilden Avenue
3                 East Side Nursing Home Inc             62 Prospect Street
4                       Wellsville Manor LLC             4192a Bolivar Road
5          Harris Hill Nursing Facility, LLC 560 Delaware Avenue, Suite 400
6                            Endo Group, LLC             400 Endo Boulevard
7      Western Region Health Corporation Inc            346 Delaware Avenue
8                      Good Shepherd Hospice        110 Bi-County Boulevard
9                      NYU Langone Hospitals               550 First Avenue
10      Endoscopy Center of Long Island, LLC             711 Stewart Avenue
   Operator.Address.2 Operator.City Operator.State Operator.Zip.Code
1                        Binghamton       New York             13905
2                      New Hartford       New York             13413
3                            Warsaw       New York             14569
4                        Wellsville       New York             14897
5                           Buffalo       New York             14202
6                       Garden City       New York             11530
7                           Buffalo       New York             14202
8           Suite 114   Farmingdale       New York             11735
9                          New York       New York             10016
10                      Garden City       New York             11530
   Cooperator.Name Cooperator.Address Cooperator.Address.2 Cooperator.City
1                                                                         
2                                                                         
3                                                                         
4                                                                         
5                                                                         
6                                                                         
7                                                                         
8                                                                         
9                                                                         
10                                                                        
   Cooperator.State Cooperator.Zip.Code             Ownership.Type
1          New York                  NA Not for Profit Corporation
2          New York                  NA Not for Profit Corporation
3          New York                  NA       Business Corporation
4          New York                  NA                        LLC
5          New York                  NA                        LLC
6          New York                  NA                        LLC
7          New York                  NA       Business Corporation
8          New York                  NA Not for Profit Corporation
9          New York                  NA Not for Profit Corporation
10         New York                  NA                        LLC
         Facility.Location                   geometry
1  (42.097095, -75.975243)  POINT (-75.97524 42.0971)
2   (43.05497, -75.228828) POINT (-75.22883 43.05497)
3   (42.738979, -78.12867) POINT (-78.12867 42.73898)
4  (42.126461, -77.967834) POINT (-77.96783 42.12646)
5   (42.956268, -78.68856) POINT (-78.68856 42.95627)
6  (40.733765, -73.591286) POINT (-73.59129 40.73376)
7  (42.893864, -78.875824) POINT (-78.87582 42.89386)
8  (40.725994, -73.428329) POINT (-73.42833 40.72599)
9  (40.734818, -73.983231) POINT (-73.98323 40.73482)
10 (40.732571, -73.607971) POINT (-73.60797 40.73257)
Show the code
library(ggplot2)
library(dplyr)
library(sf)

# Filter data for Bronx and plot
ggplot(data = NYS_health_sf %>%
         dplyr::filter(Facility.County == "Bronx")) +
  geom_sf(aes(color = Ownership.Type)) +  # Replace 'descriptor' with the appropriate column if needed
  coord_sf(xlim = c(-73.97, -73.78), ylim = c(40.92, 40.79), default_crs = st_crs(4326)) +
  theme_minimal()

Show the code
library(ggplot2)
library(dplyr)
library(sf)

# Filter data for Bronx and plot
ggplot(data = NYS_health_sf %>%
         dplyr::filter(Facility.County == "New York")) +
  geom_sf(aes(color = Ownership.Type)) +  # Replace 'descriptor' with the appropriate column if needed
  coord_sf(xlim = c(-74.04, -73.9), ylim = c(40.88, 40.7), default_crs = st_crs(4326)) +
  theme_minimal()

Show the code
# Filter data for Bronx RHCs
Bronx_health_sf <- NYS_health_sf %>%
  dplyr::filter(Facility.County == "Bronx" & Description == "Residential Health Care Facility - SNF") 

mapview(Bronx_health_sf, zcol='Ownership.Type', layer.name='Bronx R.H.C.F')
Show the code
# Create the plot
ggplot(data = Bronx_health_sf) +
  geom_sf(aes(color = Description)) +  # Corrected column name
  coord_sf(xlim = c(-73.97, -73.78), ylim = c(40.92, 40.79), default_crs = sf::st_crs(4326)) +  # Removed incorrect 'crs'
  labs(title = "RHCs in the Bronx", subtitle = "Residential Health Care Facilities - SNF") +
  theme_minimal()

Show the code
NYS_health_sf$Facility.Open.Date <- as.Date(NYS_health_sf$Facility.Open.Date, format="%m/%d/%Y")

# Create a simple ggplot
ggplot(data = NYS_health_sf) +
  geom_bar(aes(x = Facility.County, fill = as.factor(Facility.County))) +
  theme_minimal() +
  labs(title = "Count of Facilities by County", 
       x = "County", 
       y = "Facility Count") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))