Skip to content

Instantly share code, notes, and snippets.

@jebyrnes
Last active August 29, 2015 14:19
Show Gist options
  • Save jebyrnes/bb0a37b376757938c003 to your computer and use it in GitHub Desktop.
Save jebyrnes/bb0a37b376757938c003 to your computer and use it in GitHub Desktop.
A demo of leaflet using a color legend
#devtools::install_github("rstudio/leaflet", ref="feature/color-legend")
library(leaflet)
library(RColorBrewer)
set.seed(100)
pdf <- data.frame(Latitude = runif(100, -90,90), Longitude = runif(100, -180,180))
#make a property with colors
pdf$Study <- rep(1:10,10)
#need to create a pal using colorbin
pal = colorBin('RdYlBu', as.numeric(pdf$Study), 5)
#the map with a legend
leaflet(pdf) %>% addTiles() %>%
addCircleMarkers(lat = ~ Latitude, lng = ~ Longitude, color= pal(pdf$Study)) %>%
addLegend(pal = pal, values = pdf$Study, title="Study")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment