Coordinates, facets, and composition API
On this page
Examples
Coordinate methods flip, zoom, or change the coordinate system, facet methods split a plot into panels by a field, and Compose places separate plots side by side or in a grid. Facets and composition shows them with examples.
Coordinates and facets: coordFlip() · coordPolar() · coordFixed() · coordCartesian() · facetWrap() · facetGrid()
Compose: Compose::beside() · Compose::stack() · Compose::grid() · $compose->title() · $compose->theme() · $compose->resolve() · $compose->raw() · $compose->toArray() · $compose->toSpec()
Functions: coord_flip() · coord_polar() · coord_fixed() · coord_equal() · coord_cartesian() · facet_wrap() · facet_grid()
Coordinates and facets
coordFlip()
->coordFlip(bool $flip = true): PlotSwaps the x and y channels, so mappings stay as written while the plot turns sideways.
Function: coord_flip().
coordPolar()
->coordPolar( string $theta = 'x', float $start = 0.0, int $direction = 1, int|float $innerRadius = 0,): PlotPolar coordinates for bar() and col() layers, as ggplot2’s coord_polar. theta: ‘y’ turns stacked bars into a pie (map x to a constant, or leave it out; innerRadius in pixels makes a donut), and ‘x’ turns bars over a discrete x into a rose of equal angles with radius y. start rotates the first slice clockwise from twelve o’clock, in radians; direction -1 runs anticlockwise.
Function: coord_polar().
coordFixed()
->coordFixed(int|float $ratio = 1): PlotA fixed aspect ratio, as ggplot2’s coord_fixed: one unit of y takes ratio times the length of one unit of x. The panel’s height follows from the width (300 pixels unless set) and the data ranges, which are kept exact.
Functions: coord_fixed(), coord_equal().
coordCartesian()
->coordCartesian(?array $xlim = null, ?array $ylim = null): PlotZooms to fixed domains, clipping marks outside them.
Function: coord_cartesian().
facetWrap()
->facetWrap( array|string $facets, ?int $ncol = null, ?int $nrow = null, string $scales = 'fixed', array|string $labeller = 'value', array $header = [],): PlotSmall multiples wrapped into rows. scales: fixed, free, free_x, free_y. With several fields the panels are their combinations. labeller: ‘both’ labels panels “field: value”, as ggplot2’s label_both.
Function: facet_wrap().
facetGrid()
->facetGrid( ?string $rows = null, ?string $cols = null, string $scales = 'fixed', array|string $labeller = 'value', array $header = [],): PlotA grid of panels by rows and/or cols fields.
Function: facet_grid().
Compose
Compose::beside()
Compose::beside(Chart ...$charts): ComposeCharts side by side in one row, as patchwork’s p1 + p2 (a Vega-Lite hconcat).
Compose::stack()
Compose::stack(Chart ...$charts): ComposeCharts stacked in one column, as patchwork’s p1 / p2 (a Vega-Lite vconcat).
Compose::grid()
Compose::grid(array $charts, int $columns = 2): ComposeA grid filled row by row with the given number of columns.
$compose->title()
->title(string $title, ?string $subtitle = null): ComposeA title and subtitle over the whole composition.
$compose->theme()
->theme(?string $preset = null, mixed ...$options): ComposeA theme preset and options for the whole composition, as Plot::theme().
$compose->resolve()
->resolve(array $resolve): ComposeShares or separates scales, axes, and legends across the plots, e.g. [‘scale’ => [‘color’ => ‘independent’]].
$compose->raw()
->raw(array $spec): ComposeDeep-merges raw Vega-Lite into the composition’s top level, as Plot::raw() does.
$compose->toArray()
->toArray(): arrayThe composition’s Vega-Lite specification.
$compose->toSpec()
->toSpec(): arrayThe composition’s specification for nesting in another composition: without $schema or config.
Functions
coord_flip()
coord_flip(): ClosureThe pipe form of ->coordFlip().
coord_fixed()
coord_fixed(int|float $ratio = 1): ClosureThe pipe form of ->coordFixed().
coord_equal()
coord_equal(int|float $ratio = 1): ClosureThe pipe form of ->coordFixed().