plot
plot copied to clipboard
Add an example
See this in the README: "TODO An example of assigning categorical colors in a scatterplot by descending count to maximize discriminability"
I'm struggling a bit with this idea; it seems we would need two marks, one "fake" that does aggregation and sorts the color domain, and the unaggregated scatterplot. But then it's better to define the domain with d3.groupSort. https://observablehq.com/@observablehq/example-of-sorting-1003
In the meantime I suggest we remove the TODO (#1023).
Here is a (contrived) demonstration of what I meant: https://observablehq.com/d/0fe77f38052f53f0
OK! Would this simpler example work? Sorts the color domain by "rain, sun, fog, drizzle, snow".
Plot.plot({
width,
color: { legend: true },
marks: [
Plot.link(weather, {
x: "date",
y1: "temp_min",
y2: "temp_max",
stroke: "weather",
sort: { color: "stroke", reduce: "count", reverse: true }
})
]
})
https://observablehq.com/@observablehq/example-of-sorting-1003
I published my notebook above. I think it’s good enough and it has accompanying explanatory text.