library(leaflet)

# Set up the color palette and breaks
colors <- c("#FFEDA0", "#FED976", "#FEB24C", "#FD8D3C", "#FC4E2A", "#E31A1C",  "#BD0026", "#800026")
bins <- c(-Inf, 10, 20, 50, 100, 200, 500, 1000, Inf) + 0.00000001
pal <- colorBin(colors, NULL, bins)

us.states <- RJSONIO::fromJSON("~/Downloads/us-states.json")

# Add custom styles to the GeoJSON features (states)
us.states$features <- lapply(us.states$features, function(feature) {
  density <- feature$properties$density
  feature$style <- list(
    weight = 2,
    opacity = 1,
    color = 'white',
    dashArray = '3',
    fillOpacity = 0.7,
    fillColor = pal(feature$properties$density)
  )
  return(feature)
})

leaflet() %>% setView(-96, 37.8, 4) %>%
  addTiles() %>%
  addGeoJSON(us.states)