Comments (5)
Hey @CIOData,
I'm happy to take a look. Can you provide a reproducible example with code?
from leaflegend.
Sure. Here is a simple example that shows the base functionality of addLegend
in leaflet, followed by two examples of using labelFormat()
, followed by the base functionality of using leaflegend.
library(tidyverse)
library(leaflet)
library(leaflegend)
df<-data.frame(x=rnorm(100),y=rexp(100,2),z=runif(100))
pal<-colorBin("PuOr",df$z,bins=c(0,.1,.4,.9,1))
#base functionality
leaflet(df) %>%
addTiles() %>%
addCircleMarkers(~x,~y,color=~pal(z),group="circles") %>%
addLegend(pal=pal,values=~z,group="circles",position="bottomleft") %>%
addLayersControl(overlayGroups=c("circles"))
#change separator to " to "
leaflet(df) %>%
addTiles() %>%
addCircleMarkers(~x,~y,color=~pal(z),group="circles") %>%
addLegend(pal=pal,values=~z,
labFormat=labelFormat(between=" to "),
group="circles",position="bottomleft") %>%
addLayersControl(overlayGroups=c("circles"))
#display as an interval of percentages with percent sign
leaflet(df) %>%
addTiles() %>%
addCircleMarkers(~x,~y,color=~pal(z),group="circles") %>%
addLegend(pal=pal,values=~z,
labFormat=labelFormat(
prefix="(",suffix=")%",between=",",
transform=function(x)100*x
),
group="circles",position="bottomleft") %>%
addLayersControl(overlayGroups=c("circles"))
#use leaflegend
leaflet(df) %>%
addTiles() %>%
addCircleMarkers(~x,~y,color=~pal(z),group="circles") %>%
addLegendBin(pal=pal, values = ~z, position = 'bottomleft') %>%
addLayersControl(overlayGroups=c("circles"))
from leaflegend.
This feature might be added in the future but currently the way to do it is:
breaks <- c(0,.1,.4,.9,1)
df$bins <- cut(df$z, breaks, paste(head(breaks, 4), tail(breaks,4), sep = ' to '))
pal <- colorFactor('PuOr', df$bins)
leaflet(df) %>%
addTiles() %>%
addCircleMarkers(~x,~y,color=~pal(bins),group="circles") %>%
addLegendFactor(pal=pal, values = ~bins, position = 'bottomleft', ) %>%
addLayersControl(overlayGroups=c("circles"))
from leaflegend.
Thanks. I had to hack this a little more because I'm using it in a dynamic environment, but it works.
from leaflegend.
from leaflegend.
Related Issues (20)
- Add Symbols List to Readme
- group layer functionality for addLegendImage not working HOT 14
- Add Line Weight Size Legend HOT 5
- icons not rendering in addLegendAwesomeIcon() HOT 1
- Add "addSymbols" and "addSymbolsSize" HOT 1
- Add leaflet recipes sheet HOT 1
- Columns in Legend HOT 2
- adjust labels of addLegendSize HOT 9
- Add NA to addLegendNumeric and ability to override labels HOT 1
- labels for addLegendFactor throw error HOT 3
- support for dashed lines in leaflet legend HOT 3
- Underscores in group layer functionality does not work for legends HOT 5
- New feature to have Stacked or nested bubbles sizeson legend when plotting bubbles in tmap HOT 1
- Group names not unique over many maps - addLayersControl gets confused in Quarto HOT 2
- Horizontal addLegendNumeric Has Poor Alignment Between Gradient and Labels HOT 6
- Bins function does not work properly HOT 9
- Change label format of addLegendQuantile() ? HOT 2
- Unwanted extra icon in legend HOT 1
- Add control on min and max size of symbols HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from leaflegend.