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.
Show the code
require(tidyverse);
Loading required package: tidyverse
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.2.0 ✔ readr 2.1.6
✔ forcats 1.0.1 ✔ stringr 1.6.0
✔ ggplot2 4.0.2 ✔ tibble 3.3.1
✔ lubridate 1.9.5 ✔ tidyr 1.3.2
✔ purrr 1.2.1
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
Show the code
require(sf);
Loading required package: sf
Linking to GEOS 3.13.0, GDAL 3.8.5, PROJ 9.5.1; sf_use_s2() is TRUE
Show the code
require(mapview);
Loading required package: mapview
Show the code
require(magrittr)
Loading required package: magrittr
Attaching package: 'magrittr'
The following object is masked from 'package:purrr':
set_names
The following object is masked from 'package:tidyr':
extract
R Spatial Lab Assignment # 1
#Load the Packages
Show the code
#Loading the Packagesoptions(repos =c(CRAN ="https://cloud.r-project.org"))# Load a list of packages. Install them first if they are not available.# The list of packages to be installedlist.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");# Check out the packages that have not been installed yet.new.packages <- list.of.packages[!(list.of.packages %in%installed.packages()[,"Package"])]# Install those missing packages first. It could take a long time for the first time.if(length(new.packages)>0) install.packages(new.packages)
Warning: packages 'maptools', 'rgeos', 'rgdal', 'ggsn' are not available for this version of R
Versions of these packages for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
Show the code
# Load all packages.lapply(list.of.packages,function(x) {require(x,character.only =TRUE,quietly =TRUE)})
Attaching package: 'raster'
The following object is masked from 'package:dplyr':
select
Attaching package: 'ggpubr'
The following object is masked from 'package:raster':
rotate
ℹ Google's Terms of Service: <https://mapsplatform.google.com>
Stadia Maps' Terms of Service: <https://stadiamaps.com/terms-of-service>
OpenStreetMap's Tile Usage Policy: <https://operations.osmfoundation.org/policies/tiles>
ℹ Please cite ggmap if you use it! Use `citation("ggmap")` for details.
Attaching package: 'ggmap'
The following object is masked from 'package:magrittr':
inset
To access larger datasets in this package, install the spDataLarge
package with: `install.packages('spDataLarge',
repos='https://nowosad.github.io/drat/', type='source')`
Attaching package: 'Matrix'
The following objects are masked from 'package:tidyr':
expand, pack, unpack
Attaching package: 'spatialreg'
The following objects are masked from 'package:spdep':
get.ClusterOption, get.coresOption, get.mcOption,
get.VerboseOption, get.ZeroPolicyOption, set.ClusterOption,
set.coresOption, set.mcOption, set.VerboseOption,
set.ZeroPolicyOption
install.packages("sf") # run once if not installed
The downloaded binary packages are in
/var/folders/dm/sj7012g577qdnv76gj2_szd80000gp/T//Rtmpt2Ly0E/downloaded_packages
Show the code
install.packages("tidyverse")
The downloaded binary packages are in
/var/folders/dm/sj7012g577qdnv76gj2_szd80000gp/T//Rtmpt2Ly0E/downloaded_packages
Show the code
library(sf)library(tidyverse)
ZIP CODE DATA CODE
Show the code
# read the file zip_sf <-st_read("Zip_Code_040114.shp")
Reading layer `ZIP_CODE_040114' from data source
`/Users/heliosselene/Desktop/Hunter/R-Spatial/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)
Convert to sf object (longitude first, latitude second)
nys_retail_food_store_xy_sf <- st_as_sf( nys_clean_data, coords = c(“x”, “y”), # X = longitude, Y = latitude crs = 4326 )
#check structure
str(nys_retail_food_store_xy_sf)
make a plot
plot(st_geometry(nys_retail_food_store_xy_sf))
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.
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"
Source Code
---title: "R Week 07 Assignment"author: "Caitlin Cacciatore"date: "3/12/2026"format: html: toc: true toc-location: left code-fold: true code-summary: "Show the code" code-tools: true---install.packages('knitr')library(knitr)## Explanation of the templateUpdate 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.```{r setup, include=FALSE}knitr::opts_chunk$set(echo =TRUE)```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 load_packages, include=TRUE}require(tidyverse);require(sf); require(mapview); require(magrittr)```## R Spatial Lab Assignment \# 1#Load the Packages```{r Pre_Task_Requisites_Loading_Packages, include=TRUE}#Loading the Packagesoptions(repos =c(CRAN ="https://cloud.r-project.org"))# Load a list of packages. Install them first if they are not available.# The list of packages to be installedlist.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");# Check out the packages that have not been installed yet.new.packages <- list.of.packages[!(list.of.packages %in%installed.packages()[,"Package"])]# Install those missing packages first. It could take a long time for the first time.if(length(new.packages)>0) install.packages(new.packages)# Load all packages.lapply(list.of.packages,function(x) {require(x,character.only =TRUE,quietly =TRUE)})install.packages("sf") # run once if not installedinstall.packages("tidyverse")library(sf)library(tidyverse)```# ZIP CODE DATA CODE```{r Zip_Code_Data, include=TRUE}# read the file zip_sf <-st_read("Zip_Code_040114.shp")#clean the datazip_nyc <- zip_sf %>%filter(!is.na("Zip Code"))nyc_zip_sf <-st_as_sf(zip_nyc,crs =4326)# create fancy plotsplot(nyc_zip_sf)```# Health Facilities Code ```{r Health_Facilities_Code, include=TRUE}# read the fileNY_Health_df <-read_csv("NYS_Health_Facility.csv", show_col_types =FALSE, lazy =FALSE) # checking structurestr(NY_Health_df)#clean the dataNY_Health_df_clean <- NY_Health_df %>%filter(!is.na(`Facility Longitude`) &!is.na(`Facility Latitude`))# Convert to sflibrary(sf)NY_Health_sf <-st_as_sf( NY_Health_df_clean,coords =c("Facility Longitude", "Facility Latitude"),crs =4326)# create a nice little (simple) plotplot(st_geometry(NY_Health_sf),xlim=c(-70,-80),ylim=c(40,45))plot(st_geometry(NY_Health_sf["Facility Zip Code"]),xlim =c(-80, -71),ylim =c(40, 46))```# RETAIL FOOD STORES CODE# I could not get this part to render despite an hour of attempts. Please forgive # that this is not in code format; and please advise on how I could render it# in the future. Many thanks. install.packages("janitor")library(janitor)nys_retail_food_store_xy_df <- read_csv("nys_retail_food_store_xy.csv", show_col_types = FALSE, lazy = FALSE) %>%str(nys_retail_food_store_xy_df)# Remove rows with those missing coordinatesnys_clean_data <- nys_retail_food_store_xy_df %>% filter(!is.na("x") & !is.na("y"))# Convert to sf object (longitude first, latitude second)nys_retail_food_store_xy_sf <- st_as_sf( nys_clean_data, coords = c("x", "y"), # X = longitude, Y = latitude crs = 4326)#check structurestr(nys_retail_food_store_xy_sf)# make a plotplot(st_geometry(nys_retail_food_store_xy_sf))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.### task 1:```{r R-spatial-assignment-task 1, include=TRUE}smpCode <-"hello, R markdown and RPubs!"cat(smpCode)```### task 2:Quarto markdown is different from R markdown in terms of chunk options. See [chunk options](https://quarto.org/docs/computations/r.html#chunk-options) at Quarto website.```{r}#| label: R-spatial-assignment-task 2#| echo: TRUEprint("This is the new code chunk options available in Quarto Markdown")```