Limiting the number of Ticks when using GroupX

Hi all,

First-time post, so please feel free to provide feedback on my formatting.

When doing a simple plot, I can pass ticks into the X or Y axis to limit the number of tick marks likes this:

Plot.plot({
  width: width,
  y: {
    grid: true,
    label: "↑ Count"
  },
  color: {
    legend: true,
  },
  x: {
    ticks: 18,
  },
  marks: [
    Plot.line(groupedByType, {
      x: "1",
      y: "2",
      z: "0",
    })
  ]
})

However, when I’m using GroupX, this is ignored

Plot.plot({
  width: width,
  color: {
    legend: true
  },
  y: {
    grid: true,
    label: "Number of Funds"
  },
  x: {
    label: "Year",
    ticks: 10,
  },
  marks: [
    Plot.barY(
      allFunds,
      Plot.groupX(
        { y: "count" },
        {
          x: (d) => new Date(d.establishedDate).getUTCFullYear(),
          fill: "Fund Type",
        },
      )
    ),
    Plot.ruleY([0])
  ]
})

This is causing my labels to run into each other as shown here:

SCR-20220612-bkw

I’m using private data so I can’t share a notebook, but I could probably spend some time anonymizing if it would be helpful.

Thanks in advance.

You should use Plot.binX and Plot.rectY when x is a quantitative or temporal dimension. You can also use the interval option as shorthand with Plot.rectY (and then you don’t need to specify the bin or group transform manually). This approach will give you the standard temporal axis and automatic ticks, and will also accurately show when you have gaps in your data (missing years).

Thanks @mbostock. That was ridiculously easy. Is there a notebook anywhere that explains the difference between bin and group and when it’s appropriate to use which?

I guess you did define the difference. Quantitative and temporal.

That’s right, yes. The bar mark and group transform are for ordinal/categorical/nominal/discrete data, while the rect mark and bin transform are for quantitative/temporal/continuous data. The respective notebooks try to point to each other but I just added a few more cross links which I hope help.