suppressWarnings({library(tidyverse)
library(tmap)
library(ggplot2)
library(units)
library(sf)
library(dplyr)
library(leaflet)
library(tidycensus)
library(leafsync)
library(dbscan)
library(sfnetworks)
library(tigris)
library(tidygraph)
library(plotly)
library(osmdata)
library(here)})
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.3.6 ✔ purrr 0.3.4
## ✔ tibble 3.1.8 ✔ dplyr 1.0.9
## ✔ tidyr 1.2.0 ✔ stringr 1.4.0
## ✔ readr 2.1.2 ✔ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## udunits database from C:/Program Files/R/R-4.2.1/library/units/share/udunits/udunits2.xml
##
## Linking to GEOS 3.9.1, GDAL 3.4.3, PROJ 7.2.1; sf_use_s2() is TRUE
##
## To enable caching of data, set `options(tigris_use_cache = TRUE)`
## in your R script or .Rprofile.
##
##
## Attaching package: 'tidygraph'
##
##
## The following object is masked from 'package:stats':
##
## filter
##
##
##
## Attaching package: 'plotly'
##
##
## The following object is masked from 'package:ggplot2':
##
## last_plot
##
##
## The following object is masked from 'package:stats':
##
## filter
##
##
## The following object is masked from 'package:graphics':
##
## layout
##
##
## Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright
##
## here() starts at C:/Users/lvillaquiran3/CP-8883/CP8883/FinalMaps
options(tigris_use_cache = TRUE)
March18delay<- read.csv("specificMarchDaysDelayData.csv")
data_stats <- readRDS("NJ_TRACTS_FINAL.rds")
data_stats2 <- data_stats %>% mutate(pct_black = race.black*100/ population) %>%
mutate(pct_white = race.white*100/ population) %>%
replace(., is.na(.), 0)
head(data_stats2)
## Simple feature collection with 6 features and 13 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -74.49146 ymin: 40.41582 xmax: -74.17981 ymax: 40.7721
## Geodetic CRS: NAD83
## GEOID hhincome population race.tot race.white race.black poverty.ratio
## 1 34023004700 67481 4202 4202 2815 566 167
## 2 34023006103 71106 5115 5115 2877 762 84
## 3 34023006500 119833 7116 7116 4701 196 252
## 4 34013000500 31761 1847 1847 663 223 250
## 5 34013002500 35208 3906 3906 64 3594 770
## 6 34013004300 26222 2624 2624 15 2548 379
## unemployed disability.status.emp no.vehic real.est.taxes
## 1 55 89 187 7000
## 2 222 105 67 7146
## 3 273 178 0 10001
## 4 71 34 215 6207
## 5 243 40 83 6542
## 6 197 87 300 5168
## geometry pct_black pct_white
## 1 MULTIPOLYGON (((-74.29005 4... 13.469776 66.9919086
## 2 MULTIPOLYGON (((-74.49146 4... 14.897361 56.2463343
## 3 MULTIPOLYGON (((-74.42388 4... 2.754356 66.0623946
## 4 MULTIPOLYGON (((-74.18703 4... 12.073633 35.8960476
## 5 MULTIPOLYGON (((-74.22563 4... 92.012289 1.6385049
## 6 MULTIPOLYGON (((-74.22347 4... 97.103659 0.5716463
tmap_mode("view")
## tmap mode set to interactive viewing
poverty <- tm_shape(data_stats2) +
tm_polygons("poverty.ratio",alpha=0.5, palette="Reds")
poverty
tmap_mode("view")
## tmap mode set to interactive viewing
NJ_2018_MAPS <- tm_shape(data_stats2) +
tm_polygons(col = c("pct_black", "disability.status.emp"), alpha = 0.5, palette= "Reds")
NJ_2018_MAPS
```