From ggplot2 to Interactive: CanvasXpress Now Reads ggalluvial and ggsankey Data Natively

If you build flow diagrams in R, you've probably met one of two shapes of data. ggalluvial wants either a wide table — one column per stage, one row per flow — or a long "lodes" table, where a single x column enumerates the stages and a stratum/alluvium pair tells you who went where. ggsankey has its own convention again: make_long() turns a set of categorical columns into a stepwise edge list of x → next_x and node → next_node pairs. Three packages, three data models, one visual idea: show how things move between categories over stages.

CanvasXpress's Sankey/Alluvial engine has long supported the "wide" shape — think of the classic biogeography-style plot with axis1, axis2, axis3 columns. What it didn't do until now was understand the long/lodes shape or the make_long edge-list shape directly. If your R workflow produced one of those, the resulting chart either mis-mapped the stages or collapsed a multi-stage story into a flat two-column diagram.

That gap is closed. CanvasXpress now recognizes both the ggalluvial lodes form and the ggsankey make_long form automatically, reshapes them under the hood, and renders them as proper multi-axis Alluvial or Sankey diagrams — with the stage order, node colors, and legend matching what you'd expect from the original ggplot.

Why this matters: time-series and multi-step flows, done right

A very common real-world case is a longitudinal survey: the same group of subjects answers the same question at several timepoints, and you want to see how answers shift — who stayed "Always," who moved to "Never," and so on. That data naturally comes out of R in lodes form: one row per subject per survey wave, with x = survey, stratum = response, alluvium = subject.

Previously, feeding that straight into the chart engine produced a flattened two-column diagram that didn't represent the time dimension correctly. Now, the engine detects the lodes structure, reshapes it into one column per survey wave, and renders a true N-stage alluvial — each column is a timepoint, each ribbon traces a subject's response across waves, and ribbon thickness reflects aggregate weight. The chart you see matches the three-survey story the data actually tells, not a collapsed two-column approximation.

The same applies to ggsankey::make_long() data — for example, a Titanic-style breakdown of Class → Sex → Age → Survived. Because make_long output is a stepwise edge list rather than a per-passenger path, CanvasXpress aggregates identical paths and builds the corresponding multi-stage diagram, reproducing ggsankey's own visual conventions: each node colored by its own category value, each ribbon colored by the node it flows from, consistent gaps between strata, and columns that don't artificially stretch to fill the full chart height. A matching legend for the node categories is drawn automatically, with colors and stage ordering lifted straight from the original factor levels, so what you see in CanvasXpress lines up with the ggplot reference.

What you get without extra work

If your chart comes from an R-to-CanvasXpress conversion of an existing ggalluvial/ggsankey plot, there's nothing new to configure — the detection and reshaping happen automatically based on the aesthetics your plot already uses (stratum/alluvium/x, or node/next_node/x/next_x). The tool recognizes which data model it's looking at and routes it to the right diagram structure.

If you're building a chart directly against CanvasXpress's JavaScript API with already-reshaped (wide) data — one column per stage — the familiar Sankey/Alluvial configuration still applies:

var cx = new CanvasXpress("chartContainer", data, {
  graphType: "Sankey",
  sankeyAxes: ["ms153_NSA", "ms432_NSA", "ms460_NSA"]
});

Once the chart is on screen, the usual tools apply. You can use Save as JSON from the chart's File menu to capture the exact chart state, including the reshaped multi-axis structure, and reload it later by dragging that saved file onto a chart container. If you want to walk back through how a given chart was constructed, the toolbar's Reproduce action replays it step by step — handy for understanding or sharing how a conversion produced the final diagram.

A note on color fidelity

One subtlety worth calling out: ggalluvial's lodes-form plots can, in principle, recolor each segment of a ribbon independently as it crosses strata. CanvasXpress's flow model colors a ribbon by a single attribute for its whole length, so the lodes path colors flows by the first stage's category — a deliberate, documented simplification rather than a bug. Everything else about the structure — stage count, stage labels, node identity per stage, and ribbon weights — matches the source plot faithfully. The ggsankey path, by contrast, reproduces per-node coloring exactly, since that's how ggsankey itself colors nodes and ribbons.

Try it

If you've been exporting ggalluvial or ggsankey charts and noticing the stage structure didn't survive the trip, it's worth revisiting — longitudinal survey data, multi-step categorical flows (admissions funnels, patient pathways, customer journeys), and any make_long-style edge list should now come through as a properly structured, interactive, multi-stage diagram, ready for the same zooming, filtering, and export tools you already use elsewhere in CanvasXpress.