Guides
Facets and composition
Small multiples
facetWrap() draws one panel per level of a field and wraps them into rows. ncol: or nrow: sets the layout. scales: is fixed, free, free_x, or free_y. Statistical layers, such as the linear fits below, are computed per panel.
use Phiz\Datasets;
use Phiz\Plot;
$plot = Plot::of(Datasets::mpg())
->aes(x: 'displ', y: 'hwy')
->point(alpha: 0.5)
->smooth(method: 'lm', color: '#D62728')
->facetWrap('drv', ncol: 3)
->size(180, 160);labeller: 'both' labels panels as “field: value”, as ggplot2’s label_both does. A map such as labeller: ['f' => 'Front', 'r' => 'Rear'] renames values, and a grid takes one map per field: labeller: ['drv' => [...], 'year' => [...]]. header: passes Vega-Lite header properties such as labelFontWeight.
facetGrid() lays panels out by a rows: field and a cols: field.
use Phiz\Datasets;
use Phiz\Plot;
$plot = Plot::of(Datasets::mpg())
->aes(x: 'hwy')
->histogram(binwidth: 2)
->facetGrid(rows: 'year', cols: 'drv', scales: 'free_y')
->size(160, 100);size() sets the size of each panel when a plot is faceted. Reference lines and curve() layers appear in every panel.
Composition
Compose::beside(), Compose::stack(), and Compose::grid() lay out separate plots as patchwork does for ggplot2. A composition takes a title, a theme, and Vega-Lite resolve rules for shared or independent scales and legends.
use Phiz\Compose;
use Phiz\Datasets;
use Phiz\Plot;
$faithful = Datasets::faithful();
$plot = Compose::beside(
Plot::of($faithful)->aes(x: 'eruptions', y: 'waiting')->point(alpha: 0.5)->size(280, 240),
Plot::of($faithful)->aes(x: 'waiting')->histogram(binwidth: 3)->coordFlip()->size(120, 240),
)->title('Old Faithful: eruption length and waiting time');Selections defined in one plot of a composition can filter or highlight the others. Interaction shows a linked brush.
From phpstats/phiz@bc7ed3e.