I chose these values judging from the histogram with 7+ bins. I am crudely trying to group similar values while trying to create the biggest difference between groups. Like a rough jenks algorithm.
Thresholds takes an array of group maximums in .doman(), and then the desired color groups in .range(). In this case we are manually entering maximums based upon my intuition. In the previous example, we calculated maximums using a natural breaks function, and then handed that to scaleThreshold to create our mapping.
With 7+ bins, I can loosely make out 4 different groups. The first group is the small bar between 0-2, the next group is where the majority of the distribution is between 2-10. The next group is between 10-16, and then lastly another small group between 16 - 22.
scaleLinear() creates a linear mapping between input and output values.
.domain() specifies the minimum and maximum values of your data. You can manually achieve this, or just use the extent function which will return an array containing the min and max of your data.
.range() will specify the two colors you want to be used for the minimum and maximum values respectively. We enter the two colors as an array of strings, either containing hexcodes or built in colors like "white", "grey", etc.
scaleQuantile creates an quantile mapping from input values (our data) to colors.
unlike scaleLinear, our .domain() needs to be an array of our data, not just the minimum and maxium.
.range() will specify the number of groups created via the array length, as well as the colors associated with each group.
This is a sly way of using Jenks Natural breaks, where we calculate the maximums for each natural break group, and then pass the array of those maximums to .domain().
The scaleQuantize() function maps input values to colors based on an equal interval grouping method. To use it, we need to specify the minimum and maximum values of the input range using .domain(), as well as the number of color groups using .range().
The function then divides the range of input values into equal intervals based on the number of color groups specified, and maps each interval to a corresponding color value.
Read in our csv data. This is where one could normalize a variable by population, but in my case percent of adult population that is obese or "Per_Adults_Diabetes" is already normalized. I divided the value by 1, just to demonstrate that I know how to normalize if warranted.
This is taking the data we read in and storing it as an array that can be used with d3's data mapping functions. This helps with analysis and visualization of the data.