Skip to content

"group" distinct value #2196

Answered by mythmon
aboveyunhai asked this question in Q&A
Discussion options

You must be logged in to vote

Having non-shared axes for faceted charts comes up occasionally. The normal answer here is to make multiple charts that each have their own distinct axes, and then control any axis that needs to be shared. Here's an example of that: https://observablehq.com/d/e047d12f66d50640

htl.html`${d3
  .sort(
    d3.groups(data, (d) => d.group),
    (d) => d[0]
  )
  .map(([groupNum, groupData]) =>
    Plot.plot({
      marginLeft: 100,
      x: { grid: true, domain: xDomain },
      y: { label: `letter (group ${groupNum})` },
      marks: [
        Plot.barX(groupData, { y: "letter", x: "frequency", sort: { y: "-x" } })
      ]
    })
  )}`

This is common enough that there is probably room for Plot…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by aboveyunhai
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants