Interactive visualization of crime in Vancouver

This is an interactive visualization of the rate of crime (mischief) in each neighborhood in Vancouver. This map can be used to easily see which neighborhood has the highest rate of crime and therefore should take caution in those areas.

## rgdal: version: 1.5-23, (SVN revision 1121)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 3.2.1, released 2020/12/29
## Path to GDAL shared files: C:/Users/Ashley/Documents/R/win-library/4.0/rgdal/gdal
## GDAL binary built with GEOS: TRUE 
## Loaded PROJ runtime: Rel. 7.2.1, January 1st, 2021, [PJ_VERSION: 721]
## Path to PROJ shared files: C:/Users/Ashley/Documents/R/win-library/4.0/rgdal/proj
## PROJ CDN enabled: FALSE
## Linking to sp version:1.4-5
## To mute warnings of possible GDAL/OSR exportToProj4() degradation,
## use options("rgdal_show_exportToProj4_warnings"="none") before loading rgdal.
## Overwritten PROJ_LIB was C:/Users/Ashley/Documents/R/win-library/4.0/rgdal/proj
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:data.table':
## 
##     between, first, last
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
## Loading required package: ggplot2
## -- Attaching packages --------------------------------------- tidyverse 1.3.0 --
## v tibble  3.1.0     v stringr 1.4.0
## v tidyr   1.1.2     v forcats 0.5.1
## v purrr   0.3.4
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::between()   masks data.table::between()
## x dplyr::filter()    masks stats::filter()
## x dplyr::first()     masks data.table::first()
## x dplyr::lag()       masks stats::lag()
## x dplyr::last()      masks data.table::last()
## x purrr::transpose() masks data.table::transpose()
## -- Attaching packages -------------------------------------- tidymodels 0.1.2 --
## v broom     0.7.5      v recipes   0.1.15
## v dials     0.0.9      v rsample   0.0.9 
## v infer     0.5.4      v tune      0.1.3 
## v modeldata 0.1.0      v workflows 0.2.1 
## v parsnip   0.1.5      v yardstick 0.0.7
## -- Conflicts ----------------------------------------- tidymodels_conflicts() --
## x dplyr::between()   masks data.table::between()
## x scales::discard()  masks purrr::discard()
## x dplyr::filter()    masks stats::filter()
## x dplyr::first()     masks data.table::first()
## x recipes::fixed()   masks stringr::fixed()
## x dplyr::lag()       masks stats::lag()
## x dplyr::last()      masks data.table::last()
## x yardstick::spec()  masks readr::spec()
## x recipes::step()    masks stats::step()
## x purrr::transpose() masks data.table::transpose()
crime_data = as.data.table(crime_data)
crime_tab = crime_data[NEIGHBOURHOOD!=""]
coordinates(crime_tab) = c("Longitude","Latitude")
crs.geo1 = CRS("+proj=longlat")
proj4string(crime_tab) = crs.geo1
plot(crime_tab, pch = 20, col = alpha("#F9B7DA",0.50))

vancity = readOGR(dsn = "./data", layer = "local-area-boundary")
proj4string(vancity) = crs.geo1
crime_agg = aggregate(x=crime_tab["TYPE"],by=vancity,FUN=length)

qpal = colorBin("Reds", crime_agg$TYPE, bins=10)
leaflet(crime_agg) %>%
  addPolygons(stroke=TRUE,opacity = 1, fillOpacity = 0.5, smoothFactor = 0.5,color="black",fillColor = ~qpal(TYPE),weight = 1) %>%
  addLegend(values=~TYPE, pal=qpal,title="Number Of Crimes Committed")