phpstats / phiz
A ggplot2-flavored grammar of graphics for PHP that emits Vega-Lite
Requires
- php: >=8.3 <8.6
- ext-json: *
Requires (Dev)
- opis/json-schema: ^2.4
- orchestra/testbench: ^10.0
- pestphp/pest: ^4.0
- phpstats/phibble: ^0.5 || ^0.6 || ^0.7
- phpstats/phit-polyfill: ^0.4
- phpstats/phplyr: ^0.4
- squizlabs/php_codesniffer: ^3.13
Suggests
- illuminate/view: For the <x-phiz> Blade component (auto-discovered in Laravel)
- phpstats/phibble: Data frames that phiz plots directly
- phpstats/phit-polyfill: Formula predictions (effect_plot, marginal_means) without the phit extension
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-02 11:12:39 UTC
README
A ggplot2-flavored grammar of graphics for PHP that emits Vega-Lite.
phiz describes a chart as data, mappings from columns to visual properties, and layers of marks, as R's ggplot2 does. It compiles the description to a Vega-Lite specification. The browser draws the specification with vega-embed, and the vl-convert binary renders it to SVG, PNG, or PDF.
PHP 8.5+:
use Phiz\Datasets; use function Phiz\{aes, geom_point, geom_smooth, ggplot, labs}; $plot = ggplot(Datasets::mpg(), aes(x: 'displ', y: 'hwy')) |> geom_point(alpha: 0.6) |> geom_smooth(method: 'lm') |> labs(x: 'Displacement (L)', y: 'Highway mpg'); $plot->save('chart.html');
PHP 8.3–8.4:
use Phiz\Datasets; use Phiz\Plot; $plot = Plot::of(Datasets::mpg()) ->aes(x: 'displ', y: 'hwy') ->point(alpha: 0.6) ->smooth(method: 'lm') ->labs(x: 'Displacement (L)', y: 'Highway mpg'); $plot->save('chart.html');
Installation
composer require phpstats/phiz
phiz supports PHP 8.3, 8.4, and 8.5 (composer.json allows >=8.3 <8.6), and CI tests all three. It has no required dependencies beyond PHP. These are optional:
- the vl-convert binary, for SVG, PNG, and PDF export
- Laravel, for the
<x-phiz>Blade component, whose service provider is discovered automatically - phit, for predictions from formula fits in the statistics helpers
Documentation
The documentation is at https://phiz.phpstats.org/docs:
- Get started builds and saves a first chart.
- Coming from ggplot2 translates ggplot2 code and lists the differences.
- Gallery shows the 46 examples in
examples/catalog.phpwith their code. - Functions and methods lists every function and method, with links to their signatures.
Development
composer test
composer lint
Development covers the test layers, the gallery, and how the documentation is rendered.
License
MIT