Skip to content

stat_summary_2d

stat_summary_2d(
    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,
    fun: Literal | None = None,
    bins: Number | Sequence[Number] | None = None,
    binwidth: Number | Sequence[Number] | None = None,
    drop: bool | None = None,
    na_rm: bool | None = None,
    **other_args: Any,
) -> LayerSpec

Summarise z over a grid of rectangles (stat="summary2d"), as ggplot2.

The grid follows geom_bin2d. Computes ..value.. (fun of the bin's z), which fill is mapped to, and the bin sizes.

Parameters:

  • mapping (FeatureSpec, default: None ) –

    Aesthetic mapping from aes(); needs x, y and z.

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

    Layer data; inherits the plot data when None.

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

    Geom that draws the bins (tiles sized by the bin).

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

    Position adjustment: a name 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, or "none" (HTML output).

  • fun ((mean, median, sum, count, min, max), default: "mean" ) –

    The summary of each bin's z.

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

    Number of bins along x and y (one number for both).

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

    Bin width along x and y; wins over bins.

  • drop (bool, default: True ) –

    False keeps bins without data, with a missing value.

  • na_rm (bool, default: None ) –

    True removes rows with missing values silently.

  • **other_args (Any) –

    Constant aesthetics and the geom's options.

Returns:

  • LayerSpec –

    The layer.

Examples:

>>> from ggrust import *
>>> data = {"lon": [1, 2, 2, 3, 4, 4], "lat": [1, 1, 2, 3, 3, 4],
...         "rain": [20, 35, 30, 10, 5, 8]}
>>> plot = ggplot(data, aes("lon", "lat", z="rain")) + stat_summary_2d(bins=4)