Skip to content

stat_slab

stat_slab(
    mapping: FeatureSpec | None = None,
    *,
    data: PlotData | None = None,
    geom: str | None = None,
    position: Position | None = None,
    show_legend: bool | None = None,
    inherit_aes: bool | None = None,
    manual_key: ManualKey | None = None,
    tooltips: Tooltips | None = None,
    orientation: str | None = None,
    density: Literal | None = None,
    bandwidth: Literal["dpi", "nrd0", "nrd"]
    | Number
    | None = None,
    adjust: Number | None = None,
    trim: bool | None = None,
    n: int | None = None,
    normalize: Literal | None = None,
    scale: Number | None = None,
    side: Literal | None = None,
    na_rm: bool | None = None,
    **other_args: Any,
) -> LayerSpec

Density slab of y per x: a filled density on one side of each x.

As stat_slab in the R package ggdist, for sample data. Computes ..pdf.., ..cdf.., ..thickness.. (the pdf, drawn) and ..n.. per group and x. The slab's thickness is normalized so the layer's largest reaches scale of the x slot.

Parameters:

  • mapping (FeatureSpec, default: None ) –

    Aesthetic mapping from aes(). Needs y (and usually x), or x with a discrete y for horizontal slabs.

  • data (DataFrame or dict, default: None ) –

    Layer data; inherits the plot data when None.

  • geom (str, default: "slab" ) –

    Geom that draws the density.

  • position (str or FeatureSpec, default: None ) –

    Position adjustment, e.g. position_dodge(width=0.9); none by default.

  • show_legend (bool, default: None ) –

    False hides this layer from the legend.

  • inherit_aes (bool, default: None ) –

    False ignores the plot's default mapping for this layer.

  • manual_key (str or FeatureSpec, default: None ) –

    This layer's key in a manual legend: a label, or layer_key().

  • tooltips (FeatureSpec or list of str, default: None ) –

    Tooltip content: layer_tooltips(), a list of column names, or "none".

  • orientation (str, default: None ) –

    "y" draws along the y axis; a discrete y with a continuous x picks it.

  • density ((bounded, unbounded), default: "bounded" ) –

    "bounded" reflects the density at bounds estimated from the data, so bounded data (proportions, positive values) keep their edges. "unbounded" is R's density().

  • bandwidth ((dpi, nrd0, nrd), default: "dpi" ) –

    Bandwidth rule (Sheather-Jones direct plug-in by default; it falls back to "nrd0" for samples too sparse for it) or a bandwidth.

  • adjust (float, default: 1 ) –

    Multiplies the bandwidth.

  • trim (bool, default: True ) –

    False extends an unbounded density 3 bandwidths beyond the data and keeps a bounded one up to its bounds.

  • n (int, default: 501 ) –

    Number of points the density is evaluated at.

  • normalize ((all, groups, none), default: "all" ) –

    "all": the layer's largest thickness reaches scale; "groups": every slab's does; "none": thickness as computed.

  • scale (float, default: 0.9 ) –

    Share of the x slot a thickness of 1 fills.

  • side ((topright, bottomleft, both), default: "topright" ) –

    Where the slab grows from x ("top", "right", "bottom" and "left" are aliases).

  • na_rm (bool, default: None ) –

    True removes rows with missing values silently.

  • **other_args (Any) –

    Constant aesthetics (fill, alpha, color, size) and width (the slot, in x resolutions, default 1).

Returns:

  • LayerSpec –

    The layer.

Raises:

  • SpecError –

    If density, side, normalize or bandwidth is not an accepted name, or a number is not positive.

  • UnsupportedValueError –

    If a number option is not a number.

Examples:

>>> from ggrust import *
>>> data = {"diet": ["veg"] * 6 + ["meat"] * 6,
...         "weight": [61, 58, 66, 70, 63, 59, 72, 80, 77, 69, 85, 74]}
>>> plot = ggplot(data, aes("diet", "weight", fill="diet")) + stat_slab()