Plot geo - map US state

I am using Plot Geo and trying to map the total count of legislative bills to US states. I have a BarY chart below that represents the dataset. The PLOT example maps data at the county level, but I am having a hard time translating it to the just the state.

Any help will be appreciated. Thanks.

You could try and use this mark:

    Plot.geo(
      bills,
      Plot.groupZ(
        {
          fill: "count",
          geometry: ([state]) =>
            states.features.find((d) => d.properties.name === state)
        },
        { geometry: "state", z: "state" }
      )
    )

It groups the bills by “state”, and returns the color as the count of bills, and the geometry as the state feature with a name that matches.

You could also count the number of bills for each state using the fill channel like so:

Plot.geo(states, { fill: (d) => d3.sum(bills, (b) => b.state === d.properties.name) })

Thanks - that works!

Both solutions work - appreciate the help!

1 Like

Mike’s solution is better!

1 Like