Skip to content

stat_bin

stat_bin(
    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,
    tooltips: Tooltips | None = None,
    orientation: str | None = None,
    bins: int | None = None,
    binwidth: Number | None = None,
    center: Number | None = None,
    boundary: Number | None = None,
    breaks: Breaks | None = None,
    color_by: str | None = None,
    fill_by: str | None = None,
    na_rm: bool | None = None,
    **other_args: Any,
) -> FeatureSpec

Count rows in bins of x (stat="bin"); drawn as a histogram by default.

Computes ..count.., ..density.., ..sumprop.. and ..sumpct...

stat_bin(...) is geom_histogram(stat="bin", ...); another geom draws the same computed rows with that geom.

Parameters:

  • mapping (FeatureSpec, default: None ) –

    Aesthetic mapping from aes().

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

    Layer data; inherits the plot data when None.

  • geom (str, default: None ) –

    Geom that draws the computed rows, by name; "histogram" when None.

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

    Position adjustment: a name such as "dodge" or a position_*() spec.

  • 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.

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

    Tooltip content: layer_tooltips(), a list of column names, or "none" to disable tooltips (HTML output).

  • orientation (str, default: None ) –

    Set to "y" to draw the geom along the y axis.

  • bins (int, default: None ) –

    Number of bins (30 when neither bins nor binwidth is set).

  • binwidth (float, default: None ) –

    Width of the bins; overrides bins.

  • center (float, default: None ) –

    A bin center, to align the bins.

  • boundary (float, default: None ) –

    A bin boundary, to align the bins.

  • breaks (list of float, default: None ) –

    Bin boundaries; overrides bins, binwidth, center and boundary.

  • color_by (str, default: None ) –

    Aesthetic the color scale applies to ("color" or "fill").

  • fill_by (str, default: None ) –

    Aesthetic the fill scale applies to ("fill" or "color").

  • na_rm (bool, default: None ) –

    True removes rows with missing values silently; otherwise they are removed with a warning.

  • **other_args (Any) –

    Options of the geom and constant aesthetics such as color="red".

Returns:

  • FeatureSpec –

    The layer.

Examples:

>>> from ggrust import *
>>> data = {"height": [150, 152, 158, 160, 161, 163, 165, 168, 170, 171, 175, 182]}
>>> plot = ggplot(data, aes("height")) + stat_bin(bins=5)