Skip to content

Instantly share code, notes, and snippets.

@walkerke
Created August 4, 2016 20:08
Show Gist options
  • Save walkerke/d9c778563ba9651e0b26f9bef32625df to your computer and use it in GitHub Desktop.
Save walkerke/d9c778563ba9651e0b26f9bef32625df to your computer and use it in GitHub Desktop.
library(leaflet)
library(tigris)
library(sp)
compare_urban_metro <- function(metro_name) {
cbsa <- core_based_statistical_areas(cb = TRUE, resolution = '20m')
ua <- urban_areas(cb = TRUE)
dfw_cbsa <- cbsa[cbsa$NAME == metro_name, ]
o <- over(dfw_cbsa, ua, returnList = TRUE)
dfw_ua <- ua[ua$NAME10 %in% o[[1]]$NAME10, ]
leaflet() %>%
addTiles() %>%
addPolygons(data = dfw_cbsa) %>%
addPolygons(data = dfw_ua, color = 'red', fillColor = 'red')
}
compare_urban_metro("Dallas-Fort Worth-Arlington, TX")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment