Last active
August 29, 2015 14:19
-
-
Save jebyrnes/bb0a37b376757938c003 to your computer and use it in GitHub Desktop.
A demo of leaflet using a color legend
This file contains 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
#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