First create a variable that names what your classification. For a linear scale, or unclassed map, this would be:
linear = d3.scaleLinear().domain([]).range([])
The min and max values are inserted in the .domain() portion as either .domain([d3.min(data),d3.max(data)]) or as .domain(d3.extent(data))
The colors will be placed in the .range portion as strings.
You want to put an equal number of colors in range as there are values in the domain.
You want a color scheme that makes sense. Websites like colorbrewer.org can help.
When using a site that helps you to pick colors, you want to make sure to find a color scheme that is set to the number of classes that you wish to create.
How to create a map with quantile classification:
Like unclassed maps, start by creating a variable that names the type of classification.
For a quantile classification, the code that the variable is set to will be the following:
quantile = d3.scaleQuantile()
.domain(data)
.range(["color1", "color2", "color3"])
Quantile classification is where each class has an equal number of features and assigns the same number of data values to each class. For example if your dataset has 100 values and you have 5 classes, each class will have 20 values. This can lead to distorted maps if the data is skewed in one direction so that values which are very dissimilar, but next to each other when they're lined up sequentially can appear as though they're the same. For this reason, you want to avoid adding in too many classes.
The number of classes in this type of classification usually matches up to some form of ordinal grouping, such as low, medium, high or 0%-25%,26%-50%, 51%-75%, 76%-100%.
In general to determine an appropriate number of classes for a classified map, you can use the goodness of absolute median deviation (GAMD) formula. This formula is 1 - (the sum of absolute deviations about class medians / the sum of absolute deviations about the median)
How to create a map with natural breaks classification:
Start by creating a variable that creates an array (list) of break points in the data. You can name this variable naturalbreaks. The naturalbreaks variable will be set to simple.ckmeans(data, *number of breaks you want*).map(v => v.pop())
You can then create a new variable that is similar to other classifications.
For a natural breaks classification, the code that the variable is set to will be the following:
d3.scaleThreshold().domain(naturalbreaks).range(["color1", "color2", "color3"]). The number of colors should equal the number of natural breaks you have set.
Jenks natural breaks classification uses an algorithm to find the most logical breaking points for where data could be grouped together to be most similar. This is useful when there is a high degree of variation within the data, but not as much so with data that is more evenly distributed. In this way, it is somewhat of the opposite of quantile classification in where it is appropriate to use.
How to create a map with equal interval classification:
Start by creating a variable that names the type of classification.
For an equal interval classification, the code that the variable is set to will be the following:
quantize = d3.scaleQuantize()
.domain(d3.extent(data)
.range(["color1", "color2", "color3"])
Equal Intervals creates classes that occupy an equal space along the number line. This should not be used for data that is heavily skewed as there might be entire classes that are either empty or only have a very small number of values.