🏠 back to Observable

Sorting error in Plot

I am working on this ensemble notebook (link below) with Plot (very excited about the much shorter and simpler code than d3), and cannot seem to use d3.sort for this particular graph ( Time Span of All (Major) Parties in West Bengal Elections: 1952-2021). I want the political parties to be sorted with the oldest born first, but everything that I have tried have not changed the alphabetical order. I tried using d3.sort, but got error: d3.sort is not a function. Help, please!

West Bengal Elections

Thanks,
Rini

in the configuration for y you could set the domain in the order you prefer:

y: {
  axis: null,
  domain: sortedParties
    .sort((a,b) => d3.ascending(a.Start, b.Start))
    .map(d => d.Party_Name)
}
2 Likes

That works! Thanks so very much!

All the best,
Rini

1 Like

Just wanted to say thanks for suggesting this! I had been trying to mess around with Plot.sort without much luck, and this was much easier to get a handle on.

1 Like