xvvvyz
June 25, 2024, 10:41pm
1
Hello! I would like to create a chart like this:
The color scale, which also represents sex, is redundant with x, allowing us to suppress the x axis and instead rely on the color legend to help the reader understand the chart’s encodings. The facets (representing sports) are separated by making the...
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()
xvvvyz
June 26, 2024, 2:11pm
3
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',
},
),
)