Grouped bar chart with temporal bins

Hello! I would like to create a chart like this:

Instead of faceting over a nominal value (sport), I would like to bin time by month.

Example data structure:

[{ Time: <date object>, Value: <value 1> | <value 2> }]

I would like to have two vertical bars with different colors indicating the frequency of value 1 and value 2 respectively within each bin.

The closest I have gotten is stacked bars with the following:

Plot.rectY(
  data,
  Plot.groupX(
    { y: 'count' },
    {
      fill: 'Value',
      interval: 'month',
      x: 'Time',
      y: 'Value',
    },
  ),
)

Any help is appreciated.

You’ll have to use binX instead of groupX since your x values are temporal. You may also want to either drop y: 'Value' or change the bin’s reduce to y: 'sum'.

Here’s a simple example using the olympians sample dataset:

Plot.rectY(
  olympians,
  Plot.binX(
    {y: "count"},
    {x: "date_of_birth", fill: "sex", interval: "year"}
  )
).plot()

Thanks for the quick response @mootari. I ended up getting what I wanted like this:

P.barX(
  data,
  P.groupY(
    { x: 'count' },
    {
      fill: 'Value',
      fy: (d) => P.timeInterval('month').floor(d.Time),
      y: 'Value',
    },
  ),
)