Skip to content

stat_bin2d

stat_bin2d(
    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,
    bins: int | Sequence[int] | None = None,
    binwidth: float | Sequence[float | None] | None = None,
    drop: bool | None = None,
    color_by: str | None = None,
    fill_by: str | None = None,
    na_rm: bool | None = None,
    **other_args: Any,
) -> FeatureSpec

Count rows in rectangular bins of x and y (stat="bin2d"); drawn as tiles by default.

Computes ..count.. and ..density...

stat_bin2d(...) is geom_bin2d(stat="bin2d", ...); another geom draws the same computed rows with that geom.

Parameters:

  • mapping (FeatureSpec, default: None ) –

    Aesthetic mapping from aes(): x, y (required), fill, color, alpha, size, linetype, width, height, weight.

  • 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; "bin2d" when None.

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

    Position adjustment: a name such as "identity" 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).

  • bins (int or list of int, default: [30, 30] ) –

    Number of bins along x and y; one number is used for both axes.

  • binwidth (float or list of float, default: None ) –

    Bin width along x and y (a None entry keeps bins for that axis); wins over bins.

  • drop (bool, default: True ) –

    False also draws the empty bins (count 0).

  • 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 = {"x": [1, 2, 2, 3, 3, 3, 4, 4, 5], "y": [2, 1, 2, 3, 2, 3, 4, 3, 5]}
>>> plot = ggplot(data, aes("x", "y")) + stat_bin2d(bins=[4, 4])