I’m a big fan of Plot but one thing I can’t figure out is how to facet a choropleth. For instance, take the Choropleth Plot example: Plot: Choropleth / Observable | Observable and imagine that you have a yearly time series of unemployment data. Is there an obvious way to facet on year?
The only way I can figure out how to do it would be to create a geometry object for each county-year combination, which seems excessive because it would mean making many copies of the same geometries.
Excellent, @Fil. I had not realized you could specify a Geo mark that way. I’d suggest showing this way of constructing a choropleth (faceted or not) in the docs or as an example (or maybe I’ve just missed this). This seems like a more natural way of making a choropleth than embedding the data in the feature properties or constructing a Map as a fips based data lookup.
Good point too about the objects not really being copied.
@Cobus I saw that example, but it appears to assume that your geodata and your “other” data are already merged, which I think is an odd assumption for the docs given that the tutorials and templates assume you are starting from a “blank” set of geodata (like the U.S. Map template) to which you will bringing, say, a csv. Unless I’m missing something, the method suggested by that example would require a user to either pull in another library to merge their data to the feature properties or to construct a new geoJSON object by hand.
Also I would suggest that the example is confusing in that it references a walmart dataset that is different from the one in other examples. For example, I might expect to be able to copy and paste that example into this notebook and have it work: Plot: Map small multiples / Observable | Observable but I’m pretty sure it doesn’t.
I like this approach as it results in simpler and easier to manage code than squeezing attributes into the geoJSON properties.
However, I’ve come across one problem: In the normal approach of supplying a geoJSON to Plot.geo(), one can encase its options object inside Plot.centroid to get tooltips or point-based symbols. But this doesn’t appear to work if one uses your suggested geometry element approach.
Is there way to use Plot.centroid (which is nice because it is so concise), or would you have to generate centroid coordinates explicitly with, say, d3.polygonCentroid()?
Thanks! There is a small difference between the two approaches that we have to be aware of, wrt non-available data. When you map “from the features” you can style N/A as grey with, say, specifying the unknown option of the color scale to be gray. When you map from the data, every feature must be present in the dataset (and in each facet), otherwise you get holes in the map. (The problem can be solved by different means: by laying out a gray background on the whole map, or by making a full join of some sort.)