R Markdown

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

Including Plots

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.

library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5     ✓ purrr   0.3.4
## ✓ tibble  3.1.4     ✓ dplyr   1.0.7
## ✓ tidyr   1.1.3     ✓ stringr 1.4.0
## ✓ readr   2.0.1     ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(sf)
## Linking to GEOS 3.8.1, GDAL 3.2.1, PROJ 7.2.1
library(raster)
## Loading required package: sp
## 
## Attaching package: 'raster'
## The following object is masked from 'package:dplyr':
## 
##     select
## The following object is masked from 'package:tidyr':
## 
##     extract
shoreline=st_read("Shoreline.shp")
## Reading layer `Shoreline' from data source 
##   `/Users/andersonoak13/Desktop/Saint Martin's/Fall 21/ENV 395 GIS/Week 8/Tobias Maps Project/Tobias Maps Project/Shoreline.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 1 feature and 6 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: -123.1086 ymin: 37.69325 xmax: -122.3277 ymax: 37.92975
## Geodetic CRS:  WGS84(DD)
shoreline = st_crop(shoreline,c(xmin = -122.6,xmax = 0,ymin = 0,ymax  = 37.9))
## Warning: attribute variables are assumed to be spatially constant throughout all
## geometries
streets = st_read("StreetCenterlines.shp")
## Reading layer `StreetCenterlines' from data source 
##   `/Users/andersonoak13/Desktop/Saint Martin's/Fall 21/ENV 395 GIS/Week 8/Tobias Maps Project/Tobias Maps Project/StreetCenterlines.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 16241 features and 21 fields
## Geometry type: LINESTRING
## Dimension:     XY
## Bounding box:  xmin: -122.5136 ymin: 37.70702 xmax: -122.3583 ymax: 37.83213
## Geodetic CRS:  WGS84(DD)
streets = streets %>% dplyr::select(classcode)
streets = streets %>% 
  filter(classcode == "1")
trees = read_csv("Street_Tree_Map.csv")
## Rows: 191278 Columns: 18
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (11): qLegalStatus, qSpecies, qAddress, qSiteInfo, PlantType, qCaretaker...
## dbl  (7): TreeID, SiteOrder, DBH, XCoord, YCoord, Latitude, Longitude
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
spec(trees)
## cols(
##   TreeID = col_double(),
##   qLegalStatus = col_character(),
##   qSpecies = col_character(),
##   qAddress = col_character(),
##   SiteOrder = col_double(),
##   qSiteInfo = col_character(),
##   PlantType = col_character(),
##   qCaretaker = col_character(),
##   qCareAssistant = col_character(),
##   PlantDate = col_character(),
##   DBH = col_double(),
##   PlotSize = col_character(),
##   PermitNotes = col_character(),
##   XCoord = col_double(),
##   YCoord = col_double(),
##   Latitude = col_double(),
##   Longitude = col_double(),
##   Location = col_character()
## )
trees = trees %>% 
  dplyr::select(PlantType, qSpecies,Latitude,Longitude) %>% na.omit()
trees = trees %>% filter(Latitude < 37.9 & Latitude > 37.6)

sycamores = trees %>% 
  filter(str_detect(qSpecies,"Sycamore"))
sycamores_sf = sycamores %>% st_as_sf(coords=c("Longitude","Latitude"),crs = 4326)
DEM = raster("DEM_SF.tif")

DEM_tr = projectRaster(DEM,crs = crs(shoreline))
DEM_tr_df = as.data.frame(DEM_tr, xy = TRUE)
ggplot(data = shoreline) +
  geom_sf() +
  geom_sf(data = streets) +
  geom_sf(data = sycamores_sf,size=.01,color = "green") +
  geom_raster(data = DEM_tr_df,aes(x=x,y=y,fill = DEM_SF),
              alpha=.5,)

library(ggplot2)
library(ggthemes)
DEM_crop = DEM_tr_df %>% 
  filter(x > -122.54 &
         x < -122.35 &
         y > 37.7 &
         y < 37.82)
ggplot(data = shoreline) +
  geom_sf(size = .2) +
  geom_sf(data = streets) +
  geom_sf(data = sycamores_sf,size=.01,color = "green") +
  geom_raster(data = DEM_crop,aes(x=x,y=y,fill = DEM_SF),
              alpha=.8) +
  theme_bw()

library(tmap)
tm_shape(shoreline) +
  tm_polygons()

tm_shape(shoreline) +
  tm_polygons() +  
tm_shape(DEM_tr) +
  tm_raster() +
tm_shape(streets) +
  tm_lines() +
tm_shape(sycamores_sf) +
  tm_dots()
## stars object downsampled to 1099 by 910 cells. See tm_shape manual (argument raster.downsample)
## Variable(s) "NA" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.