scale_discrete ¶
scale_discrete(
aesthetic: str | Sequence[str],
*,
direction: int | None = None,
name: str | None = None,
breaks: Breaks | None = None,
labels: Labels | None = None,
lablim: int | None = None,
limits: Limits | None = None,
expand: Sequence[Number] | None = None,
na_value: Color | Number | None = None,
guide: Guide | None = None,
format: str | None = None,
scale_mapper_kind: str | None = None,
**kwargs: Any,
) -> FeatureSpec
Map any aesthetic, or several at once, as categories.
Numbers become categories too, in order of first appearance.
Parameters:
-
aesthetic(str or list of str) –The aesthetic(s) the scale maps, e.g.
"shape"or["color", "fill"]. -
direction((1, -1), default:1) –-1 reverses the colors of a color scale.
-
name(str, default:None) –Axis label or legend title.
-
breaks(list or dict, default:None) –Categories that get a tick or a legend key (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) –Maximum label length in characters; longer labels are cut.
-
limits(list, default:None) –The categories (and their order).
-
expand(list of float, default:None) –[multiplicative, additive]expansion of a position scale. -
na_value(optional, default:None) –Value drawn for missing data and data outside
limits. -
guide(str or FeatureSpec, default:None) –"legend","none", or a guide spec. -
format(str, default:None) –Label format, e.g.
".1f".labelstake precedence. -
scale_mapper_kind(str, default:None) –The color mapper, e.g.
"color_brewer". -
**kwargs(Any) –Options of the mapper (
palette=, ...) or of a position scale (position=).
Returns:
-
FeatureSpec–The scale, or a
FeatureSpecArrayof one scale per aesthetic for a list.
Raises:
-
UnsupportedValueError–If
aestheticis not a string or a list of strings. -
SpecError–If
aestheticis an empty list.
Examples:
>>> from ggrust import *
>>> data = {"x": [1, 2, 3, 4], "y": [1, 2, 3, 4], "level": [1, 2, 3, 4]}
>>> plot = ggplot(data, aes("x", "y", color="level", fill="level"))
>>> plot = plot + geom_point(shape=21, size=8, alpha=0.5)
>>> plot = plot + scale_discrete(["color", "fill"], name="Level")