Visualizing Cluster Evolution: Introducing ClustreePlot in CanvasXpress
▶ Clustree package example (prefix p)▶ Clustree package example, flipped
If you work with clustering — single-cell RNA-seq resolutions, customer segmentation sweeps, or any workflow where you re-run a clustering algorithm at increasing granularity — you've probably asked the same question over and over: how do my clusters at resolution 0.4 relate to the clusters I get at resolution 1.0? Do two coarse clusters split cleanly into finer ones, or do cells get reshuffled across group boundaries as resolution increases?
That question has a well-known visual answer: the clustree diagram — a layered tree where each row is a clustering resolution, each node is a cluster, node size reflects how many observations fall into it, and edges show how observations flow from one resolution's clusters into the next. CanvasXpress now renders this chart natively as a Scatter2D plot type, so you can generate it directly from your data without leaving the library you already use for the rest of your analysis.
How it works
A clustree plot is really a Scatter2D chart wearing a very specific layout. Instead of plotting raw (x, y) measurements, CanvasXpress computes node coordinates for you: the vertical axis (or horizontal, if you flip orientation) represents clustering resolution level, and within each level, nodes are ordered to minimize crossing edges between levels — the same kind of layered, barycenter-based ordering used in classic hierarchical/layered graph layouts.
Because it's built on Scatter2D, the chart gets to reuse machinery you already know:
- Node size encodes cluster magnitude (observation count), drawn as area-scaled bubbles.
- Node color encodes resolution level, using a discrete, qualitative palette so each row of the tree reads distinctly.
- Edges are drawn underneath the nodes, with width proportional to transition count and color shaded by transition magnitude, plus a small arrowhead pointing toward the finer-resolution child cluster, so flow direction is unambiguous even when many clusters overlap.
- Legends are generated automatically — one for node size, one for edge count (color), and one for the proportion of cells flowing into each child cluster (edge opacity) — matching what you'd expect from a dedicated clustree tool, but produced by CanvasXpress's standard legend pipeline.
Getting data in
You can feed a clustree chart in the most natural shape for clustering output: a dataset with one column per resolution (e.g., res_0.1, res_0.5, res_1.0), each holding the cluster label assigned to every observation at that resolution. CanvasXpress reshapes that matrix internally into the nodes and transition edges needed to draw the tree. If you already have a precomputed node/edge structure, you can supply it directly instead.
Configuring the chart
Turning any Scatter2D chart into a clustree plot is a matter of setting scatterType to "clustree" and adjusting a handful of dedicated options — orientation, palettes, edge styling, labels, and axis display are all exposed as ordinary configuration properties:
var cx = new CanvasXpress("chartContainer", data, {
graphType: "Scatter2D",
scatterType: "clustree",
clustreePrefix: "p",
clustreeFlip: false,
clustreeSweeps: 4,
clustreeNodePalette: "Paired",
clustreeEdgePalette: "Spectral",
clustreeEdgeArrows: true,
clustreeNodeLabels: true,
clustreeShowEdgeLegend: true
});
A few options worth knowing:
clustreePrefixtells CanvasXpress which column prefix identifies your resolution columns, and that prefix (minus the numeric suffix) becomes the axis title — so ares_0.4…res_1.0series renders as a clean "res" axis labeled 0.4 through 1.clustreeFliprotates the whole tree to run left-to-right instead of top-to-bottom, with the coarsest resolution anchored on the left — handy for wide dashboards or when you want resolution to read along the horizontal axis.clustreeSweepscontrols how many passes the crossing-reduction pass makes when ordering nodes within each level; more sweeps can produce a tidier layout on complex trees.clustreeNodeLabelsturns on cluster-id text centered on each node (automatically skipped on nodes too small to hold legible text).clustreeShowAxesis a debugging aid that reveals the raw numeric layout axes underneath the named resolution axis, if you ever need to inspect node placement directly.
Because the chart is still a standard CanvasXpress object under the hood, everything you already rely on works the same way. You can update the underlying data with cx.updateData(...) as new resolutions come in, adjust any clustree option with cx.updateConfig(...) and redraw immediately, or resize the chart with cx.setDimensions(...). Calling cx.getConfig() returns the fully resolved configuration, including every clustree-specific setting, which is useful if you're building a UI that lets users toggle orientation or palettes interactively.
Exploring and sharing
Right-clicking a clustree chart surfaces a dedicated context-menu section for flipping orientation, toggling axis display, and removing the clustree layer — no need to dig through a general settings panel. The same options are also available through CanvasXpress's visual Customizer panel, under its own Clustree tool group, for users who prefer a guided interface over editing configuration directly.
And because every CanvasXpress chart is self-describing, you get the same save/share workflow as any other plot: use Save as JSON from the chart's File menu to capture the exact chart state, drag that saved file back onto a chart container to reload it instantly, or use the Reproduce toolbar action to replay the chart's construction step by step — useful for documenting how a particular clustree layout was built, or for sharing a reproducible figure with collaborators.
Clustree plots join CanvasXpress's growing set of specialized chart types built on a shared, battle-tested rendering core — so the plot you use to explore clustering resolutions looks and behaves consistently with everything else in your dashboard.