Skip to content

ggmarginal

ggmarginal(
    sides: str,
    *,
    size: float | Sequence[float] | None = None,
    layer: LayerSpec | FeatureSpecArray,
) -> FeatureSpec

Add copies of a layer in margins of the panel: a marginal plot (as lets-plot).

Parameters:

  • sides (str) –

    The margins, any of "t", "r", "b", "l" (top, right, bottom, left), e.g. "tr".

  • size (float or list of float, default: 0.1 ) –

    The margin's height or width as a share of the plotting area (panel plus margins), in [0.01, 0.95]; a list gives one per side, in order.

  • layer (LayerSpec or FeatureSpecArray) –

    The layer to copy, e.g. geom_density(); histograms and densities in the left and right margins turn sideways, boxplots and violins sit at 0 across.

Returns:

  • FeatureSpec –

    The marginal layers.

Raises:

  • TypeError –

    If sides is not a string or size not a number or list.

  • ValueError –

    If sides names an unknown margin or size is out of range.

Examples:

>>> from ggrust import *
>>> data = {"x": [1.0, 2.0, 2.5, 3.0, 4.0], "y": [2.0, 1.0, 3.0, 2.5, 4.0]}
>>> plot = ggplot(data, aes("x", "y")) + geom_point()
>>> plot = plot + ggmarginal("tr", layer=geom_density(fill="grey"))