Charts with updated FEC filing data for Virginia’s 5th house district Democrats.
I decided to make an R package to facilitate the reuse of charts I make for the blog and am going to develop it out in the open. Since I’ve settled on a style guide, a custom charting library helps avoid hunting down old scripts and copy pasting code all the time. You are welcome to use it, though be warned it will be entirely unstable as I settle on what options to make available and it comes as is.
If you haven’t already read it, a better place to start might be the basic introduction to my responsive D3 code organization strategy. That one covers only how to code a responsive x-axis and introduces the “calc”, “update”, “draw”, and “resize” functions that I use to keep things straight in D3. This post extends that to a full chart and introduces a “load” function for bringing in data from a csv file.
Coming up with contingency plans for different display dimensions in D3 can get ugly. My recent charts all adjust for screen size, but they also have to handle different modes and view options as selected by users. I’ve quickly realized the advantages of using well-planned functions for almost everything including establishing scales, adding elements to the DOM, and modifying elements of the DOM.