Search by

phpstats / phiz

erikwestlund

A ggplot2-flavored grammar of graphics for PHP that emits Vega-Lite

Package info

github.com/phpstats/phiz

pkg:composer/phpstats/phiz

Statistics

Installs: 23

Dependents: 1

Suggesters: 1

Stars: 0

Open Issues: 1

v0.5.1 2026-10-31 15:30 UTC

This package is auto-updated.

Last update: 2026-10-31 16:43:22 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.php with their code.
  • API reference lists every method and function with its signature.

Development

composer test
composer lint

Development covers the test layers, the gallery, and how the documentation is rendered.

License

MIT