Skip to content

scale_color_steps2

scale_color_steps2(
    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,
    limits: Limits | None = None,
    n_breaks: int | None = None,
    nice_breaks: bool = True,
    right: bool = True,
    show_limits: bool = False,
    oob: Oob = "squish",
    na_value: Color | Number | None = None,
    guide: Guide | None = None,
    trans: Transform | None = None,
    format: str | None = None,
) -> FeatureSpec

Map color to binned colors of a diverging gradient (ggplot2).

Binned like scale_color_steps, colored like scale_color_gradient2.

Parameters:

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

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

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

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

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

    Colors of 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, default: None ) –

    Bin edges inside the data range (data units). Default: about n_breaks generated ones.

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

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

  • limits (list, default: None ) –

    [low, high] range of the bins. Without limits or breaks, the ends move out so the end bins are as wide as the others (ggplot2).

  • n_breaks (int, default: None ) –

    How many breaks to aim for (default 5).

  • nice_breaks (bool, default: True ) –

    Round break values; False spaces n_breaks breaks evenly over the range.

  • right (bool, default: True ) –

    Bins are closed on the right: a value on a break joins the bin below it.

  • show_limits (bool, default: False ) –

    Also label the two ends of the colorbar.

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

    What data outside limits maps to: the end bins ("squish") or na_value ("censor").

  • na_value (str, default: None ) –

    Color of missing data.

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

    "colorbar" (default, drawn as steps), "legend", "none", or a guide_colorbar() / guide_legend() spec.

  • trans (str, default: None ) –

    Transformation of the data, as in scale_color_gradient; breaks are generated in transformed units.

  • format (str, default: None ) –

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

Returns:

  • FeatureSpec –

    The scale.

Raises:

  • SpecError –

    If oob is not "squish" or "censor".

Examples:

>>> from ggrust import *
>>> data = {"x": [1, 2, 3] * 3, "y": [1] * 3 + [2] * 3 + [3] * 3,
...         "change": [-3, -1, 0, -2, 0, 2, 0, 1, 4]}
>>> plot = ggplot(data, aes("x", "y", color="change")) + geom_point(size=12)
>>> plot = plot + scale_color_steps2(midpoint=0)

Choose the three colors and the bin edges:

>>> base = ggplot(data, aes("x", "y", color="change")) + geom_point(size=12)
>>> plot = base + scale_color_steps2(
...     low="darkorange", mid="lightgrey", high="purple", breaks=[-2, -1, 1, 2]
... )

Choose the three colors and the bin edges