scale_color_d3 ¶
scale_color_d3(
palette: Literal | None = None,
alpha: float = 1,
overflow: Literal | None = None,
name: str | None = None,
breaks: Breaks | None = None,
labels: Labels | None = None,
lablim: int | None = None,
limits: Limits | None = None,
na_value: Color | None = None,
guide: Guide | None = None,
format: str | None = None,
) -> FeatureSpec
Map color with the ggsci d3 palette, from D3.js.
A discrete scale (10 colors, 20 for the category20* palettes).
Not in lets-plot (R package ggsci).
Parameters:
-
palette((category10, category20, category20b, category20c), default:"category10") –ggsci palette name.
-
alpha(float, default:1) –Opacity of the palette colors, in (0, 1].
-
overflow((generate, cycle, interpolate), default:"generate") –How to get more colors than the palette has (
"g","c","i"). Default:"generate", asscale_*_brewer()for qualitative palettes. ggsci leaves the extra categories missing; ggrust colors them and warns. -
name(str, default:None) –Legend title.
-
breaks(list, default:None) –Categories that get a legend key.
-
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) of the scale. Other data gets
na_value. -
na_value(str, default:None) –Color drawn for missing data and data outside
limits. -
guide(str or FeatureSpec, default:None) –"legend","none", or aguide_legend()spec. -
format(str, default:None) –Label format: a number format (
".2f",",","%") or a template ("{.1f} %").labelstake precedence.
Returns:
-
FeatureSpec–The scale.
Raises:
-
SpecError–If
paletteis not a d3 palette name,alphais not in (0, 1], oroverflowis not an overflow name. -
UnsupportedValueError–If
paletteis not a string oralphais not a number.
Examples:
>>> from ggrust import *
>>> data = {"age": [1, 3, 5, 7, 2, 4, 6, 8, 3, 9],
... "weight": [4, 6, 6, 7, 8, 12, 14, 15, 2, 3],
... "pet": ["cat"] * 4 + ["dog"] * 4 + ["rabbit"] * 2}
>>> plot = ggplot(data, aes("age", "weight", color="pet")) + geom_point(size=5)
>>> plot = plot + scale_color_d3(palette="category20")