Make your map beautiful and statistically relevant
ClassyBrew on GitHub
When creating a choropleth map, there are generally two key questions.
- How do I classify the data? (break up the data)
- What color scheme should be used?
My favorite data classification method is called the Jenks Natural Breaks method. It calculates inherent places to break up your data based on the number of classes you want. These statistically related numeric ranges are perfect for a when you want a meaningful breakup of you data. If you are looking for an amazing writeup of the Jenks Natural Breaks, and an algorithm in Python, read the following blog post by Daniel Lewis:
What colors best represent your newly classified data? More often than most, you will be classifying your data because it follows some sequential pattern. Cynthia Brewer has spend a good chunk of her career figuring this out for you. Thank you Cynthia! Her research and cartographical background created COLORBREWER, a visual decision making tool for coloring your map to represent your data.
I recently created a map in Leaflet and needed to classify my data (geojson) and assign a color value to each sequential range. Since there is no inherent ability to render data based on associated values, you will need to do this from scratch. I found a handy chropleth example on Leaflet that did just that.
This was accomplished by manually defining your breaks and returning , again a manually assigned color:
I’m sure you can see a problem with this method. If your data changes or you want a new color palette, you have to manually change these values.
What I needed was an automatic way to do this. The pseudocode looked like:
Here is the setup:
Now we can use the Leaflet choropleth example using the newly automated generator.
Everytime we call getColor, we will now have our Jenks’ classified and ColorBrewer approved color representing the provided number.
ClassyBrew on GitHub
The library contains a simple example of using the classybrew object, as well as a minified version only 18kb in size.
Thank you to the following individuals for helping make this possible:
Cynthia Brewer - ColorBrewer
Simon Georget - GeoStats
Daniel J. Lewis - Jenks Natural Breaks Description