🏠 back to Observable

Plot, facet by month and year


I want to facet time series data by Year on the Y axis. I can get the plot showing by the domain of the X axis is the entire ~10 years, and not just the months.

I have tried to manipulate the date field, since the data for each facet is sliced by a Year column, the year for the plot doesn’t matter much:

Plot.line(sum, {
  x: (d) => new Date(2021, d.Month.getMonth(), d.Month.getDay()),
  y: "sum",
  stroke: "Year",
  curve: "step"
  marks: setRuleMarks(0, -100, 100),
  facet: {
    data: sum,
    y: "Year",
    marginRight: 50
  y: {
    ticks: 3
  height: 700,
  marginLeft: 90

It looks OK, apart from the little 2021 label at the bottom left.

But in general, is this the way to do it?

Here are two examples

1 Like

Alright, cool. Thanks.

Do you happen to know how to add spacing between the facet plots?

yes, this would be the fy: {padding: 0.1} option.

1 Like

Thanks, about the only thing I did not try :slight_smile: