Skip to content

stat_summary_bin

stat_summary_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,
    sampling: Sampling | None = None,
    tooltips: Tooltips | None = None,
    orientation: str | None = None,
    fun: Literal | None = None,
    fun_min: Literal | None = None,
    fun_max: Literal | None = None,
    fun_data: Literal | None = None,
    fun_args: Mapping[str, Number] | None = None,
    quantiles: Sequence[float] | None = None,
    bins: int | None = None,
    binwidth: Number | None = None,
    center: Number | None = None,
    boundary: Number | None = None,
    color_by: str | None = None,
    fill_by: str | None = None,
    na_rm: bool | None = None,
    **other_args: Any,
) -> LayerSpec

Summarise y in bins of x (stat="summarybin"), drawn as point ranges.

x is binned as in geom_histogram; every bin gets y, ymin and ymax (see stat_summary). Empty bins are missing and not drawn.

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: "pointrange" ) –

    Geom that draws the summary.

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

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

    lets_plot sampling; accepted and ignored, as ggrust draws every row.

  • 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 ) –

    "y" bins y and summarises x per bin.

  • fun (str, default: "mean" ) –

    Aggregate for y; see stat_summary.

  • fun_min (str, default: "min" ) –

    Aggregate for ymin.

  • fun_max (str, default: "max" ) –

    Aggregate for ymax.

  • fun_data ((mean_se, mean_sdl), default: "mean_se" ) –

    ggplot2 shortcut that sets all three; see stat_summary.

  • fun_args (dict, default: None ) –

    Arguments of fun_data: {"mult": k}.

  • quantiles (list of float, default: [0.25, 0.5, 0.75] ) –

    The probabilities of lq, mq and uq.

  • bins (int, default: 30 ) –

    Number of bins; binwidth overrides it.

  • binwidth (float, default: None ) –

    Width of the bins.

  • center (float, default: None ) –

    x value at the centre of a bin.

  • boundary (float, default: None ) –

    x value at the edge of a bin; overrides center.

  • 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 ("color" or "fill").

  • na_rm (bool, default: None ) –

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

  • **other_args (Any) –

    Constant aesthetics such as color="red", and the geom's options.

Returns:

  • LayerSpec –

    The layer.

Examples:

>>> from ggrust import *
>>> data = {"age": [21, 25, 33, 38, 41, 47, 52, 58], "income": [20, 28, 35, 40, 44, 47, 50, 49]}
>>> plot = ggplot(data, aes("age", "income")) + stat_summary_bin(binwidth=10)