knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Loading and merging the firebox data from the web

The following link allows us to download a kml file with all the firebox data: https://www.google.com/maps/d/u/0/viewer?hl=en&mid=1P57skjWUo0KYfsinVweKLAcnAHA&ll=40.71433439509608%2C-73.88551614404662&z=11 We will open all layers and merge them into a single tidy csv file.

library(sf)
library(dplyr)
layer1 = st_read(dsn = "data-raw/FDNY_Box_Locations.kml",
                 layer = "Fire_Boxes_1.csv")
layer2 = st_read(dsn = "data-raw/FDNY_Box_Locations.kml",
                 layer = "Fire_Boxes_2.csv")
layer3 = st_read(dsn = "data-raw/FDNY_Box_Locations.kml",
                 layer = "Fire_Boxes_3.csv")
layer4 = st_read(dsn = "data-raw/FDNY_Box_Locations.kml",
                 layer = "Fire_Boxes_4.csv")
layer5 = st_read(dsn = "data-raw/FDNY_Box_Locations.kml",
                 layer = "Fire_Boxes_5.csv")
layer6 = st_read(dsn = "data-raw/FDNY_Box_Locations.kml",
                 layer = "Fire_Boxes_6.csv")
layer7 = st_read(dsn = "data-raw/FDNY_Box_Locations.kml",
                 layer = "Fire_Boxes_7.csv")
layer8 = st_read(dsn = "data-raw/FDNY_Box_Locations.kml",
                 layer = "Fire_Boxes_8.csv")
layer9 = st_read(dsn = "data-raw/FDNY_Box_Locations.kml",
                 layer = "Fire_Boxes_9.csv")
nyc_map_firebox_full <- rbind(layer1, layer2, layer3, layer4, layer5, layer6, layer7, layer8, layer9)
#Tidying the data
nyc_map_firebox_full <- nyc_map_firebox_full %>% 
  mutate(Name = factor(Name))

Ploting the data

We are checking if all the data is correctly displayed

plot(nyc_map_firebox_full %>% select(Name))
#Saving the new dataset and tidying it
st_write(nyc_map_firebox_full, "data/firebox.csv", layer_options = "GEOMETRY=AS_XY", delete_dsn = TRUE)

firebox <- read.csv("data/firebox.csv")

nyc_map_firebox_full <- firebox %>% 
  rename(lon = X, 
         lat = Y)
devtools::use_data(nyc_map_firebox_full, nyc_map_firebox_full)


HenriMatalon/XHEC-R-GROUP-PROJECT-FDNY documentation built on May 31, 2019, 1:47 a.m.