statsbreaks is a javascript package whose objective is to split (to classify/to discretize) a quantitative data set into a (k) number of classes or thematic categories. The general aim is to create a choropleth map, for example with bertin.js.
statsbreaks
is javascript package to make data classification for choropleth maps.
Last version
<script src="https://cdn.jsdelivr.net/npm/statsbreaks" charset="utf-8"></script>
Pinned version
<script src="https://cdn.jsdelivr.net/npm/[email protected]" charset="utf-8"></script>
Last version
stat = require("statsbreaks")
Pinned version
stat = require("[email protected]")
The shape function allows to compute breaks according to several discretization methods. Source
Code
stat.breaks({ values: data, method: "jenks", nb: 5, precision: 0 })
Parameters
- values: an array of quantitative values
- method: method of discretization. "quantile", "q6", "equal", "jenks" or "geometric".
- nb: number of classes
- precision : rounding. 2 transform 35667.877876 to 35667.87 -2 transform 35667.877876 to 35600.
The shape function allows to draw the shape of the data. This step is important to choose the right discretization method. Source
Code
stat.shape(data, precision, marks, log)
Parameters
- data: an array of quantitative values
- precision: a number. Curve accuracy (default:25)
- marks: a boolean (default true)
- log : a boolean. transforms into a logarithm (default: false)
The view function allows to visualize the result of a discretization. Source
Code
stat.view(breaks, colors, data)
Parameters
- breaks: an array of n breaks
- colors: an array of n-1 colors (optional)
- data : the input data set to display ticks (optional)