The ‘scaleQuantize()’ Scale

Quantize scales allow for continuous data to be transformed into a discrete dataset with equal intervals.

We are going to learn about a scale called the quantize scale. Sounds scary, but I promise you it is not. Let’s talk about the problem we faced in the previous lecture.

The problem with a linear scale

We needed to transform our values into colors. We used the linear scale to accomplish this. The linear scale will transform the dataset from a continuous dataset to another continuous dataset. In our case, the output will be a continuous dataset of colors. While it is great that D3 could handle this without a problem, it was difficult to read the data. We had 100 different colors in the chart.

Rather than having 100 different colors, we should limit how many colors can be used. In other words, we should transform the data into a discrete dataset. As a reminder, data that is discrete means there are a limited number of choices. We should be able to count how many values are in a dataset if it is discrete.

The quantize scale is a scale that can transform continuous data into discrete data. It is the solution that can solve our dilemma. Before using the quantize scale, we should figure out what colors we want to transform our dataset to. Unlike last time, we need to provide every possible color the data can be transformed to. We are going to use three colors.

They will be white, pink, and red. We’re going to be using three colors because of how income is categorized in America. Typically, your income will determine which economic class you’re placed in. There is the lower, middle, and upper class. There are three classes in total. Therefore, we will have three colors to represent each class.

How the quantize scale works

I want to answer the following question: How does the quantize scale work?

Get hands-on with 1200+ tech skills courses.