Skip to content

Instantly share code, notes, and snippets.

@abresler
Forked from jebyrnes/leafletMapWithLegend.R
Last active December 18, 2015 15:35
Show Gist options
  • Save abresler/893496eb6a18ab79e8c2 to your computer and use it in GitHub Desktop.
Save abresler/893496eb6a18ab79e8c2 to your computer and use it in GitHub Desktop.
#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