-
-
Save katzkawai/38bf92e8d931272d6b7cb30034ddfa7d to your computer and use it in GitHub Desktop.
A leaflet map for R built on a shape file of US counties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # NOTE: This builds on data prep from here: https://gist.github.com/keberwein/a61651d1de90476d5fb28dc08bbbc617 | |
| # and shape file prep from here: https://gist.github.com/keberwein/815cca98e7d99fc360ab27faa651e5cc | |
| library(dplyr) | |
| library(leaflet) | |
| library(scales) | |
| library(RColorBrewer) | |
| #Format popup data for leaflet map. | |
| popup_dat <- paste0("<strong>County: </strong>", | |
| county_dat$county_name, | |
| "<br><strong>Value: </strong>", | |
| county_dat$value) | |
| pal <- colorRampPalette(c("green","green3","green2","green1","red")) | |
| #Render final map in leaflet. | |
| leaflet(data = us.map) %>% addTiles() %>% | |
| addPolygons(stroke = FALSE, fillOpacity = 0.5, smoothFactor = 0.5, popup = popup_dat, | |
| color=pal(400)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment