Skip to content

filter after group #1603

Answered by mbostock
winner106 asked this question in Q&A
May 20, 2023 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Either use the filter reducer option in the group outputs

Plot.barX(
  data,
  Plot.groupY(
    {x: "count", filter: (d) => d.length > 2},
    {
      y: "industry",
      sort: {y: "x", reverse: true}
    }
  )
)

or compose the filter transform with the group transform like you originally proposed

Plot.barX(
  data,
  Plot.filter(
    (d) => d.length > 2,
    Plot.groupY(
      {x: "count"},
      {
        y: "industry",
        sort: {y: "x", reverse: true}
      }
    )
  )
)

In either case the filter function is passed the aggregated data, which is the array of data in each group.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@winner106
Comment options

Answer selected by winner106
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants