Scatter Plots With a Categorical Axis, Done Right in CanvasXpress
▶ Scatter2D with a categorical axis
Here is a request that sounds trivial and used to be anything but: "plot this numeric measurement against this category as a scatter plot." You have a column of groups — treatment arms, regions, cell types — and a column of numbers, and you want points placed by category along one axis and by value along the other.
CanvasXpress now handles this directly. A plain Scatter2D config with a categorical column on one axis and a numeric column on the other renders real points, where you expect them, with no reshaping on your part.
new CanvasXpress("canvas", {
graphType: "Scatter2D",
xAxis: ["Region"], // a categorical column
yAxis: ["Measurement"], // a numeric column
data: { /* your table */ }
});
Why this was harder than it looks
CanvasXpress's classic scatter plot was built around a specific, powerful convention: the axes are samples. Its signature use case is comparing two sample columns across many variable rows — a replicate-correlation plot, for example, where each point is a gene and the two axes are two experiments. That convention is woven deep into how the chart renders, selects, builds legends, and draws overlays.
That design is excellent for what it was built for, but it meant a config that named a categorical variable on an axis — rather than a sample — had nothing sensible to resolve to. The practical result was a plot that quietly came out wrong. People reaching for an everyday "category versus value" scatter hit that wall.
The fix: promote the column, reuse the proven path
Rather than teach the entire rendering pipeline a second, parallel way to interpret an axis — risky, and a source of subtle bugs for years to come — CanvasXpress does something cleaner. When it sees a categorical column named on a Scatter2D axis, it promotes that column into the sample position the renderer already understands, then draws the chart through the exact same tested path everything else uses.
In other words, your "category versus value" scatter runs on the same machinery that already produces correct tooltips, selection, legends, saved images, and PDF export. You did not get a second-class rendering mode; you got the first-class one, reached by a new on-ramp.
This approach was already proven in CanvasXpress's translation layer for grammar-of-graphics-style charts, where a categorical aesthetic on an axis has always worked. What changed is that the same capability is now available to anyone writing a direct configuration by hand — or to any tool or assistant that generates one — not only to charts arriving through that one translation path.
What you get
- Points where they belong. Categories spread along one axis, values along the other, one point per observation.
- Everything else unchanged. Because the chart renders through the standard sample-indexed pipeline after promotion, hover tooltips, point selection, legends, color-by, and image/PDF export all behave exactly as they do on any other scatter plot.
- Your existing scatter plots untouched. The promotion only kicks in for the categorical-axis case. Classic sample-versus-sample scatter plots — the correlation plots CanvasXpress has always excelled at — render byte-for-byte as before. Nothing you already built moves.
- A clear signal when something is genuinely wrong. If an axis value is neither a valid category, a sample, nor a number or date — a typo, a missing column — CanvasXpress tells you, instead of silently drawing an empty plot. That warning now fires only for real dead ends, not for the perfectly reasonable categorical axis it can handle.
A small thing that removes a real friction
Most of the value here is that a very natural request now simply works. You should not have to know CanvasXpress's internal "axes are samples" convention, nor transpose your data by hand, to make a scatter plot of a measurement across a handful of groups. You describe what you want — category on x, value on y — and you get it.
If you have ever typed something like "scatter plot with a categorical x axis" and been surprised by a blank chart, that surprise is gone. Point an axis at a category column, point the other at your numbers, and CanvasXpress draws the plot you asked for. It is available today, and the result carries the same reproducibility and export guarantees as every other CanvasXpress chart.