Compatibility and limitations
Design and compatibility
Vega-Lite does the drawing
phiz does not draw graphics. It translates a ggplot2-style description into a Vega-Lite specification. Vega-Lite then resolves scales, lays out facets and legends, runs transforms, handles interaction, and renders to canvas or SVG. The PHP side stays small, and plots behave the same in the browser and in static export.
Statistics run as Vega-Lite transforms where Vega-Lite has them: bins, densities with the default bandwidth, aggregates, quantiles, and window functions. phiz computes a statistic in PHP when Vega-Lite has no equivalent, or when matching R needs it:
smooth()fits and their confidence bands (loess up to 3,000 rows,lm,quad, andpoly)- violin densities, and the R
bw.nrd0bandwidth behinddensity(adjust:) - 2D densities, contours, and filled contours
ellipse()and the summaries ofsummary()hex(), andbin2d()andhistogram()aboveConfig::$serverRowsrowsline(downsample:)curve()evaluations of PHP functions- the statistics helpers’ intervals and predictions
Mapping ggplot2 to Vega-Lite
| ggplot2 | phiz | Vega-Lite |
|---|---|---|
ggplot(data, aes(...)) |
Plot::of($data)->aes(...) |
data and encoding |
geom_*() |
->point(), ->line(), … |
a layer with a mark |
stat_*() |
geom parameters | transform |
position = "dodge" |
position: 'dodge' |
xOffset |
scale_*() |
->scaleX(), … |
the channel’s scale, axis, and legend |
coord_flip() |
->coordFlip() |
swapped channels |
facet_wrap(), facet_grid() |
->facetWrap(), ->facetGrid() |
facet with an inner spec |
theme() |
->theme() |
config |
| patchwork | Compose |
hconcat, vconcat, concat |
Differences from ggplot2
Coming from ggplot2 lists the translations and the behaviors that differ.
PHP versions
composer.json allows PHP >=8.3 <8.6: PHP 8.3, 8.4, and 8.5. CI runs the test suite on all three. The library code parses on PHP 8.3. Examples and tests that use the pipe operator |> need PHP 8.5. Each documentation example that uses it has a method-chain version, and the tests check that both build the same specification.
Vega-Lite versions
phiz emits Vega-Lite 6 specifications. The pinned browser libraries are vega 6.4.0, vega-lite 6.4.3, and vega-embed 7.3.0. Static export uses vl-convert with Vega-Lite 6.1, and the tests validate every specification against the Vega-Lite 6.1.0 JSON schema, the version both renderers support.
From phpstats/phiz@bc7ed3e.