Skip to content

geom_smooth

geom_smooth(
    mapping: FeatureSpec | None = None,
    *,
    data: PlotData | None = None,
    stat: str | None = None,
    position: Position | None = None,
    show_legend: bool | None = None,
    inherit_aes: bool | None = None,
    manual_key: ManualKey | None = None,
    sampling: Sampling | None = None,
    tooltips: Tooltips | None = None,
    labels: FeatureSpec | None = None,
    orientation: str | None = None,
    method: Literal["lm", "loess", "lowess"] | None = None,
    n: int | None = None,
    se: bool | None = None,
    level: Number | None = None,
    span: Number | None = None,
    deg: int | None = None,
    seed: int | None = None,
    max_n: int | None = None,
    color_by: str | None = None,
    fill_by: str | None = None,
    na_rm: bool | None = None,
    **other_args: Any,
) -> LayerSpec

Draw a fitted curve with a confidence band (stat="smooth"), one per group.

The computed variables are x, y (the fitted value), ymin and ymax (the band) and ..se.. (the standard error). The band uses each model's own standard error, as ggplot2 (lets_plot uses the straight-line one for every method, so its polynomial and loess bands differ).

Parameters:

  • mapping (FeatureSpec, default: None ) –

    Aesthetic mapping from aes().

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

    Layer data; inherits the plot data when None.

  • stat (str, default: None ) –

    Statistical transformation, by name; "smooth" 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.

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

    A legend key for this layer, as in lets_plot; not supported yet (ggrust warns).

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

  • labels (FeatureSpec, default: None ) –

    lets_plot's model summary annotation (smooth_labels()); not supported yet (ggrust warns).

  • orientation (str, default: None ) –

    "y" smooths x along y; not supported yet (ggrust warns).

  • method ((lm, loess, lowess), default: "lm" ) –

    Fitting method: least squares ("lm") or local regression ("loess", "lowess").

  • n (int, default: 80 ) –

    Number of points the curve is evaluated at.

  • se (bool, default: True ) –

    False leaves out the confidence band.

  • level (float, default: 0.95 ) –

    Confidence level of the band, in [0.01, 0.99].

  • span (float, default: 0.5 ) –

    Share of the points each loess fit uses, in (0, 1].

  • deg (int, default: 1 ) –

    Degree of the "lm" polynomial; 2 or more fits a polynomial.

  • seed (int, default: 37 ) –

    Seed of the row sampling for loess on more than max_n rows.

  • max_n (int, default: 1000 ) –

    Loess fits a random sample of this many rows per group when it has more.

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

    Constant aesthetics such as color="red" or fill="steelblue", as in lets_plot.

Returns:

  • LayerSpec –

    The layer.

Examples:

>>> from ggrust import *
>>> frame = {"hours": [1, 2, 3, 4, 5, 6], "score": [52, 55, 61, 64, 70, 71]}
>>> plot = ggplot(frame, aes("hours", "score")) + geom_point() + geom_smooth()