Skip to content

Instantly share code, notes, and snippets.

@katzkawai
Forked from keberwein/countyfips_leaflet.R
Created June 17, 2016 23:43
Show Gist options
  • Select an option

  • Save katzkawai/38bf92e8d931272d6b7cb30034ddfa7d to your computer and use it in GitHub Desktop.

Select an option

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
# 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