Making a Leaflet map

Leaflet is an open source JavaScript library for embedding interactive maps in webpages. It’s widley used, and there is an R package that enables you to make your own!

These maps often use GeoJSON files, a “light-weight” text-based format for storing spatial data. JSON files are specifically designed for use with JavaScript, and are much less of a hassle than shapefiles. However, GeoJSON has less funcitonality, especially with projections.

I downloaded this GeoJSON Philadelphia HOLC map from the URichmond Mapping Redlining website.

library(geojsonio)
## 
## Attaching package: 'geojsonio'
## The following object is masked from 'package:base':
## 
##     pretty
library(leaflet)

phl <- geojson_read("~/Google Drive/Computer Backup/HOLC_Philadelphia.geojson", what = "sp")

cols <- c("darkgreen","blue","yellow","red")
pal <- colorFactor(cols, sort(unique(phl$holc_grade)))

leaflet(phl) %>%
  addTiles() %>%
  addPolygons(stroke = FALSE, smoothFactor = 0.3, fillOpacity = 0.7,
              fillColor = ~pal(holc_grade), label = ~paste0(holc_id, ": ", holc_grade))