Skip to content

scale_gradient2

scale_gradient2(
    aesthetic: str | Sequence[str],
    *,
    low: Color | None = None,
    mid: Color | None = None,
    high: Color | None = None,
    midpoint: Number = 0,
    name: str | None = None,
    breaks: Breaks | None = None,
    labels: Labels | None = None,
    lablim: int | None = None,
    limits: Limits | None = None,
    oob: Oob | None = None,
    rescaler: Rescaler | None = None,
    na_value: Color | None = None,
    guide: Guide | None = None,
    trans: Transform | None = None,
    format: str | None = None,
) -> FeatureSpec

Map color aesthetics to a diverging three-color gradient.

Parameters:

  • aesthetic (str or list of str) –

    The color aesthetic(s), e.g. "fill" or ["color", "fill"].

  • low (str, default: "#964540", "#FBF9F7", "#3B3D96" ) –

    Colors at the low end, the midpoint and the high end.

  • mid (str, default: "#964540", "#FBF9F7", "#3B3D96" ) –

    Colors at the low end, the midpoint and the high end.

  • high (str, default: "#964540", "#FBF9F7", "#3B3D96" ) –

    Colors at the low end, the midpoint and the high end.

  • midpoint (float, default: 0 ) –

    Data value that gets mid.

  • name (str, default: None ) –

    Legend title.

  • breaks (list or dict, default: None ) –

    Values that get a colorbar tick (a dict maps labels to breaks).

  • labels (list of str or dict, default: None ) –

    One label per break (a dict maps breaks to labels).

  • lablim (int, default: None ) –

    Ignored on continuous scales, with a warning, as in lets-plot.

  • limits (list, default: None ) –

    [low, high] data range. Data outside the limits gets na_value.

  • oob ((censor, squish), default: "censor" ) –

    What data outside limits maps to. Not in lets-plot (ggplot2 oob).

  • rescaler (callable, default: None ) –

    rescaler(x, to, from_) maps the data to (0, 1) before the palette. Not in lets-plot (ggplot2 rescaler).

  • na_value (str, default: None ) –

    Color drawn for missing data and data outside limits.

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

    "colorbar", "legend", "none", or a guide spec.

  • trans (str, default: None ) –

    Transformation of the data, e.g. "log10" or "sqrt".

  • format (str, default: None ) –

    Label format, e.g. ".1f". labels take precedence.

Returns:

  • FeatureSpec –

    The scale, or a FeatureSpecArray of one scale per aesthetic for a list.

Raises:

Examples:

>>> from ggrust import *
>>> data = {"x": [1, 2, 3, 4, 5], "y": [3, 1, 4, 1, 5], "change": [-2, -1, 0, 1, 2]}
>>> plot = ggplot(data, aes("x", "y", color="change", fill="change"))
>>> plot = plot + geom_point(shape=21, size=10, alpha=0.4)
>>> plot = plot + scale_gradient2(["color", "fill"], low="blue", high="red")