Skip to main content
A transform reshapes the data before it’s charted — pivoting columns into rows, filtering, sorting, aggregating, or adding a constant column. Transforms run before mappings are read, so a mapping can reference columns a transform produced.

Reshape: wide to long

The most common transform. Many datasets are wide — one column per series:
But a mapping wants a long shape — one row per series, with a category column to split on:
transform.reshape pivots wide to long so you can map the new category column to color:
string[]
The numeric columns to collapse into rows. Defaults to all numeric columns.
string[]
Columns to carry through unchanged. Defaults to all categorical/temporal columns.
string
default:"key"
Name of the output column holding the original column names.
string
default:"value"
Name of the output column holding the values.

Other transforms

operator is one of 'eq', 'neq', 'gt', 'gte', 'lt', 'lte'. Note that neq belongs to this comparison vocabulary only — the highlight predicate language has no neq and writes the same idea as { not: … }. direction is 'asc' or 'desc', defaulting to 'asc'. op is one of 'count', 'sum', 'mean', 'median', 'mode', 'min', 'max'. The first four always produce a numeric output column; mode, min and max keep the source column’s type — which decides whether the result can be mapped to a continuous scale. transform.constant’s type is a DataType: 'numeric', 'categorical' or 'temporal'.

Spec-level vs layer-level

Piping a transform into the spec applies it to all layers. To reshape the data for a single geom — for example, a line overlay that needs a different shape than the bars beneath it — pass transforms on that geom:

Next