This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
library(terra)
## Warning: package 'terra' was built under R version 4.3.1
## terra 1.7.71
library(tidyterra)
## Warning: package 'tidyterra' was built under R version 4.3.1
##
## Attaching package: 'tidyterra'
## The following object is masked from 'package:stats':
##
## filter
library(sp)
## Warning: package 'sp' was built under R version 4.3.1
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.3.1
library(ggthemes)
## Warning: package 'ggthemes' was built under R version 4.3.1
library(urbnmapr)
library(sf)
## Warning: package 'sf' was built under R version 4.3.1
## Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
library(raster)
## Warning: package 'raster' was built under R version 4.3.1
##
## Attaching package: 'raster'
## The following object is masked from 'package:tidyterra':
##
## select
setwd("~/Downloads/NE1_50M_SR_W")
#Plot 1
raster <- rast("NE1_50M_SR_W.tif")
plot(raster)
crop_extent <- extent(-125, -66.9, 24.5, 49.4) #extend function from https://www.rdocumentation.org/packages/raster/versions/3.6-26/topics/extend
cropped_raster <- crop(raster, crop_extent)
plot(cropped_raster)
setwd("~/Downloads/ne_10m_admin_1_states_provinces")
baseMap <- st_read("ne_10m_admin_1_states_provinces.shp") #basemap from NaturalEarthData.com
## Reading layer `ne_10m_admin_1_states_provinces' from data source
## `/Users/mickey/Downloads/ne_10m_admin_1_states_provinces/ne_10m_admin_1_states_provinces.shp'
## using driver `ESRI Shapefile'
## Simple feature collection with 4596 features and 121 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -180 ymin: -90 xmax: 180 ymax: 83.6341
## Geodetic CRS: WGS 84
love <- plot(baseMap, add= TRUE)
## Warning in plot.sf(baseMap, add = TRUE): ignoring all but the first attribute
#Plot 2
library(leaflet)
## Warning: package 'leaflet' was built under R version 4.3.1
setwd("~/Downloads")
Leaflet_data <- st_read("Leaflet_Data.csv")
## Reading layer `Leaflet_Data' from data source
## `/Users/mickey/Downloads/Leaflet_Data.csv' using driver `CSV'
## Warning: no simple feature geometries present: returning a data.frame or tbl_df
m <- leaflet(Leaflet_data) %>%
setView(lng = -75.9180, lat = 42.0987, zoom = 4) %>% #https://www.rdocumentation.org/packages/leaflet/versions/2.2.1/topics/setView
addTiles() %>%
addMarkers(lng = -75.9180, lat = 42.0987, popup = "Broome: 20,500 ears of corn harvested") %>%
addMarkers(lng = -73.971321, lat = 40.776676, popup = "Manhattan: Not Reported") %>%
addMarkers(lng = -76.1784, lat = 43.0268, popup = "Onondaga: 14,100 ears of corn harvested") %>%
addMarkers(lng = -78.7476, lat = 42.6975, popup = "Erie: 15,500 ears of corn harvested") %>%
addMarkers(lng = -73.7562, lat = 42.6526, popup = "Albany: 2,000 ears of corn harvested") %>%
print(m)
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.