How to build an interactive choropleth map with barely any code
What you’ll need
- Data organized by U.S. state
- A spreadsheet program (like Excel, Pages or Google Sheets)
- A text editing program (like TextEdit, Sublime Text or TextWrangler)
- FTP access to your website
Getting your data into a spreadsheet
We chose to visualize the number of craft breweries by state using 2013 data from the Brewers Association.
We pasted our data into a spreadsheet Garvin provided.
Adding data to Mr. Map Generator
We then copied our whole spreadsheet and pasted it into Mr. Map Generator.
Next, we selected the column we want to visualize. We chose the most recent year of data: 2013.
Then, we selected the color, the number of shades, and the size of the “buckets” we want those shades to represent. The size of these buckets (or breaks) will depend on the story you want to tell. (This becomes a question of ethics in many cases because you don’t want to skew your distribution unequally. Here’s a short discussion about that. Here’s another that weighs the different ways to classify data breaks.) We chose completely arbitrary breaks that are not equally intervals.
Next, we previewed our map. Disregard the legend because it won’t show up when you download the data files. Garvin’s tutorial includes some steps to print this image to a PDF and extract the map and legend in Adobe Illustrator.
Downloading the data files
To make this map interactive on your own website, download Garvin’s zip package of files. Unzip the folder and open the file code.js in a simple text editor (like TextEdit) or something more heavy duty (like Sublime Text).
This is the extent of the code you will see or work with. In fact, you’re not even working with it but rather copying and pasting it. Just so you know what’s going on, you are defining the variable “data” with your state abbreviations, state names, and brewery data. Looks like a spreadsheet, right?
Finally, you save your code.js file and then upload the contents of that unzipped folder to your own folder on your server. We use the FTP software FileZilla.
To add a title, I including the following line of HTML above the map on US-map.html: <p style=”font-family:Open Sans, sans-serif; text-align: center; font-size: 1.5em;”>The number of craft breweries by state in 2013</p>.
Improvements to be made
Garvin has open-sourced part of his workflow and for that we’re immensely grateful. Some suggestions for improvement would be (1) to include a customizable legend for the shading; (2) to allow users to input HTML hexcodes for the colors of their choice; (3) to make the map responsive (scale down for mobile); (4) to allow users to set up a time series (with several years of data, for example). Still, we thank Garvin for the initiative. Add your own comments below.