Plot: Sorting Groups Question

I’ve got a sorting problem that I’d like some help on. I’ve included a link to an example notebook.

What I’d like to do is sort the categories (the package property in the dataset) by the changes property in the dataset, and not the property that was encoded as the x channel. This is all for plotting some metrics from a formatted git repo log. I’ve figured out how to plot the addition and removal metrics for each package, but I’m not sure how to sort with the property I want.

Thanks for any help.

we have an issue open for that feature sort by channel not used to visualize? · Issue #867 · observablehq/plot · GitHub

currently the best way to do this is to make the domain explicit in the y scale definition, for example with d3.groupSort:

y: {domain: d3.groupSort(data, v => d3.sum(v, d => d.changes), d => d.package).reverse()},

Thanks, @Fil. This workaround did what I needed. I’ve also republished the example above to include your suggestion in case anyone comes across this same problem in the future.