Tobias Trees

Harold Nelson

10/12/2021

Read the trees data from the Tobias collection.

Setup

library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.3     ✓ purrr   0.3.4
## ✓ tibble  3.1.2     ✓ dplyr   1.0.6
## ✓ tidyr   1.1.3     ✓ stringr 1.4.0
## ✓ readr   1.4.0     ✓ 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

Get Trees

trees = read_csv("Street_Tree_Map.csv")
## 
## ── Column specification ────────────────────────────────────────────────────────
## 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()
## )
glimpse(trees)
## Rows: 191,278
## Columns: 18
## $ TreeID         <dbl> 254276, 254270, 119263, 158174, 188702, 254275, 188697,…
## $ qLegalStatus   <chr> "Permitted Site", "Permitted Site", "DPW Maintained", "…
## $ qSpecies       <chr> "Eriobotrya deflexa :: Bronze Loquat", "Tristaniopsis l…
## $ qAddress       <chr> "102 Bache St", "399 Melrose Ave", "495X Lakeshore Dr",…
## $ SiteOrder      <dbl> NA, 3, 1, 1, 2, 1, 13, 1, 1, 2, 1, 1, 2, 2, 3, 1, 2, 1,…
## $ qSiteInfo      <chr> "Sidewalk: Curb side : Cutout", "Sidewalk: Curb side : …
## $ PlantType      <chr> "Tree", "Tree", "Tree", "Tree", "Tree", "Tree", "Tree",…
## $ qCaretaker     <chr> "Private", "Private", "DPW", "Private", "DPW", "Private…
## $ qCareAssistant <chr> "FUF", "FUF", NA, "FUF", NA, "FUF", NA, NA, "FUF", "FUF…
## $ PlantDate      <chr> "01/30/2018 12:00:00 AM", "01/30/2018 12:00:00 AM", NA,…
## $ DBH            <dbl> 3, 3, NA, 3, 17, 3, 15, NA, 3, 3, 21, 3, NA, 10, 13, 3,…
## $ PlotSize       <chr> "3x3", "3x3", "10x30", "3x3", "Width 4ft", "3x3", "Widt…
## $ PermitNotes    <chr> "Permit Number 778482", "Permit Number 781229", NA, "Pe…
## $ XCoord         <dbl> 6007159, 5997471, NA, 6004059, 6015995, 6003166, 601723…
## $ YCoord         <dbl> 2095376, 2095517, NA, 2096890, 2098219, 2109645, 209729…
## $ Latitude       <dbl> 37.73391, 37.73375, NA, 37.73789, 37.74221, 37.77286, 3…
## $ Longitude      <dbl> -122.4176, -122.4511, NA, -122.4285, -122.3873, -122.43…
## $ Location       <chr> "(37.7339080899914, -122.417644212443)", "(37.733746687…
trees = trees %>% 
  dplyr::select(PlantType, qSpecies,Latitude,Longitude) %>% na.omit()

summary(trees)
##   PlantType           qSpecies            Latitude       Longitude     
##  Length:188625      Length:188625      Min.   :37.51   Min.   :-138.3  
##  Class :character   Class :character   1st Qu.:37.74   1st Qu.:-122.5  
##  Mode  :character   Mode  :character   Median :37.76   Median :-122.4  
##                                        Mean   :37.77   Mean   :-122.4  
##                                        3rd Qu.:37.78   3rd Qu.:-122.4  
##                                        Max.   :47.27   Max.   :-122.4

Raw

Look at the raw data. Convert it to an sf object and use geom_sf().

trees_sf_raw = st_as_sf(trees,coords=c("Longitude","Latitude"), crs = 4326)

trees_sf_raw %>% ggplot() + geom_sf()

Clean

Clean the trees dataframe. There are trees too far north and too far south.

trees = trees %>% filter(Latitude < 37.9 & Latitude > 37.6)

Convert

Turn the dataframe into an sf object.

trees_sf = trees %>% st_as_sf(coords=c("Longitude","Latitude"),crs = 4326)

trees_sf %>% ggplot() + geom_sf(size = .01)

Species

trees %>% 
  group_by(qSpecies) %>% 
  summarize(count = n()) %>% 
  arrange(desc(count))
## # A tibble: 567 x 2
##    qSpecies                                                                count
##    <chr>                                                                   <int>
##  1 Platanus x hispanica :: Sycamore: London Plane                          11442
##  2 Tree(s) ::                                                              10349
##  3 Metrosideros excelsa :: New Zealand Xmas Tree                            8643
##  4 Lophostemon confertus :: Brisbane Box                                    8422
##  5 Pittosporum undulatum :: Victorian Box                                   7061
##  6 Tristaniopsis laurina :: Swamp Myrtle                                    6984
##  7 Prunus cerasifera :: Cherry Plum                                         6689
##  8 Magnolia grandiflora :: Southern Magnolia                                6235
##  9 Ficus microcarpa nitida 'Green Gem' :: Indian Laurel Fig Tree 'Green G…  5646
## 10 Arbutus 'Marina' :: Hybrid Strawberry Tree                               5562
## # … with 557 more rows

Sycamores

Get just the sycamores and plot them.

sycamores = trees %>% 
  filter(str_detect(qSpecies,"Sycamore"))
sycamores_sf = sycamores %>% st_as_sf(coords=c("Longitude","Latitude"),crs = 4326)
sycamores_sf %>% ggplot() + geom_sf(size = .1)