-
I'm working on a time series, binned weekly/monthly ( By default the ticks appear at the beginning of the rectangles, but we want them at the center. It is possible to manually set the ticks to be middle of the month/week, but seems too much hassle. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
That’s a little tricky to do with a quantitative or temporal axis, as when using rectY and binX, because the axis doesn’t have a concept of an interval—it’s continuous. Probably what you want here is to treat the temporal data as ordinal instead, which you can do using barY and groupX, in conjunction with the interval option. Here’s an example: Plot.plot({
x: {
interval: 5, // this should match the rounding below!
tickFormat: "" // don’t show a comma for years
},
marks: [
Plot.barY(olympians, Plot.groupX({y: "count"}, {x: (d) => Math.floor(d.date_of_birth.getUTCFullYear() / 5) * 5}))
]
}) https://observablehq.com/@observablehq/plot-time-series-grouped-bars That said, you can style the axis ticks so that the ticks are left-aligned, which is better for indicating that they represent the start of an interval. That’s demonstrated here: https://observablehq.com/@observablehq/plot-multiscale-date-axis And you could use that technique to center the tick labels but it’s tricky to get the date math right. |
Beta Was this translation helpful? Give feedback.
That’s a little tricky to do with a quantitative or temporal axis, as when using rectY and binX, because the axis doesn’t have a concept of an interval—it’s continuous.
Probably what you want here is to treat the temporal data as ordinal instead, which you can do using barY and groupX, in conjunction with the interval option. Here’s an example:
https://observablehq.com/@observablehq/plot-time-series-grouped-bars
That said, …