Making Hexbin maps

This project is the result of chapter 11 of Learning D3js Mapping, a book I co-authored with Oscar Villarreal and Thomas Newton. The chapter is an exploration of the hexagonal binning map which thankfully gets shortened to hexbin map.

It's a visual that didn't really start with the data — as a well-behaved visual should — but with a technique. It's an interesting process, this. Not wrangling data and their users to squeeze out the right visual, but wrangling the technique to find the right data. You should try it.

First, I decided to visualise the US. Not an immediately appealing option as it's probably the most visualised geo-shape in the universe. But then I thought it's the smallest common denominator for readers from all ends of the world. Secondly, there's just lots of data for the US.

I started out with big ideas. First, I thought: hexagons → bees. That makes sense. So I wanted to get bee data. Ideally, I'd have a dataset of all beehives across the US. So I reached out to the NASS, the National Agriculture Statistics Service — Poultry and Specialty Commodity Section. They were very nice. But only had county level data. Problem is, you need point location data for hexbins. Counts of things. Hexbin maps are the clean relative to dot density maps:

dot density map

While that didn't work, I was caught in the web of the USDA (the US Dept. of Agriculture) by that point and after a quick rendezvous with every-sheep-in-the-US-data, I ended up at Farmers Markets. Not thrilling but a nicely complete, relatively recent and politically correct dataset.

To be honest, the chapter doesn't spend much time with findings but abuses the data ruthlessly to demonstrate a relatively straight forward recipe to get to a regularly tessellated hexbin map:

hexbin making algorithm

One or two blips later…
crochet bins

Crochet bins

…I ended up with a hexbin map playground that lets you explore hexagon shaped areas across the US, play with the size of the hexagons, load different datasets and change the colour interpolators.

Fill your boots!




The code is online right here and the book lives here. Please drop me a note with questions or comments.