Comments (8)
colorBin()
is based on pretty()
, and the price of making bins "pretty" is that it is you are unlikely to get exactly n bins. If you want to get exactly n bins, the cut points will not be "pretty" (e.g. numbers with 16 digits after the decimal point).
from leaflet.
@yihui great to know, but...
I think we should clearly spilt the problem in two:
- how many bins do I want to use? I must be able to specify the number of bins I want to use, either using
colorBin
(orcolorFactor
). IfcolorBin
(orpretty()
) decides for me how many bins is using, it is not (much) useful. - what is the format of the data in the legend? On the legend data format issue I've already posted a feature request here. This discussion reinforces the need to address legend data formatting (maybe using the scale package?).
Suppose that I've used a not-pretty number of bins (e.g. with lots of decimals). I wouldn't see a problem if the legend data is just approximate: I would use a popup to display the actual value in each area to clarify any ambiguity. What would it matter to know precisely where the cut occurred? In most cases it wouldn't.
For me, a legend of a choropleth map needs to give an idea at a glance of the order of magnitude of the areas, especially if there is an easy way to get the actual detail (e.g. popup).
In any case, may I suggest to mention in the help that the number of bins are forced by pretty()
?
At the moment it says only:
colorBin also maps continuous numeric data, but performs binning based on value (see the cut function).
Thanks
from leaflet.
@yihui As a way to extend the ability to define different binning approaches, I suggest to integrate the package βclassIntβ by Roger Bivand.
from leaflet.
Thanks! I have addressed the documentation in #53, in which you will also be able to format the labels by yourself if you provide the bins
vector of non-pretty numbers. Supporting classInt is trivial in the sense that you simply call classInt::classIntervals(var, n)
and pass $brks
to bins
in colorBin()
. I'd rather not introduce the dependency on another package.
from leaflet.
π thanks (but I would prefer pretty as an option...)
from leaflet.
@smartinsightsfromdata Just added an argument pretty = TRUE
to colorBin()
, so you can choose to use exactly n bins generated from seq(min, max, length = n)
.
from leaflet.
π π
from leaflet.
I forgot to mention it was still in the PR #53 and has not been merged to the master branch yet.
from leaflet.
Related Issues (20)
- Leaflet Map not loading after window size changes
- htmlwidgets 1.6.3 breaks addEasyButton HOT 1
- Update of map not works HOT 1
- addPolyline() with SpatVector fails if terra is not loaded because check_crs_terra() is missing depency terra::crs HOT 2
- toggle baseGroups legends in the same way as overlayGroups in addLayersControl HOT 1
- Proj4Leaflet-TMS.R example is broken; broken TMS in Leaflet is possibly the culprit! HOT 2
- tms = TRUE not working with known TMS provider (from NASA!) HOT 2
- Leaflet muddling RGB rasters from terra
- No documentation on the Polyline 'offset' functionality
- Error in addLegend: unused arguments HOT 2
- addTiles does not allow display of self-hosted vector tiles
- Specifying labels as zero-length character vector causes error
- Update docs to use `{sf}` or `{terra}` HOT 1
- Remove vignettes/articles/nc after successful site build
- Broken basemaps on {pkgdown} site HOT 3
- Specifying Pop-up Location HOT 2
- modify icon size
- dependencies missing in v.2.2.2 HOT 2
- Maps are blank when previewing in RStudio on Windows with R 4.4.0 HOT 5
- Leaflet maps don't appear in RStudio Viewer Pane (Windows + R 4.4 HOT 1
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 leaflet.