Show the code
smpCode <- "hello, R markdown and RPubs!"
cat(smpCode)hello, R markdown and RPubs!
install.packages(‘knitr’)
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.
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”);
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,“Package”])]
if(length(new.packages)>0) install.packages(new.packages)
lapply(list.of.packages,function(x) { require(x,character.only = TRUE,quietly = TRUE) })
install.packages(“sf”) # run once if not installed install.packages(“tidyverse”)
library(sf) library(tidyverse)
zip_sf <- st_read(“Zip_Code_040114.shp”)
#clean the data
zip_nyc <- zip_sf %>% filter(!is.na(“Zip Code”))
nyc_zip_sf <- st_as_sf(nyc_zip,crs = 4326)
plot(nyc_zip_sf)
NY_Health_df <- read_csv(“NYS_Health_Facility.csv”, show_col_types = FALSE, lazy = FALSE)
str(NY_Health_sf)
#clean the data
NY_Health_df_clean <- NY_Health_df_clean %>% filter(!is.na(Facility Longitude) & !is.na(Facility Latitude))
library(sf)
NY_Health_sf <- st_as_sf( NY_Health_df_clean, coords = c(“Facility Longitude”, “Facility Latitude”), crs = 4326 )
plot(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))
nys_retail_food_store_xy_df <- read_csv(“nys_retail_food_store_xy.csv”, show_col_types = FALSE, lazy = FALSE)
nys_clean_data <- nys_clean_data %>% filter(!is.na(X) & !is.na(Y))
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)
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.
smpCode <- "hello, R markdown and RPubs!"
cat(smpCode)hello, R markdown and RPubs!
Quarto markdown is different from R markdown in terms of chunk options. See chunk options at Quarto website.
print("This is the new code chunk options available in Quarto Markdown")[1] "This is the new code chunk options available in Quarto Markdown"