scale_brewer ¶
scale_brewer(
aesthetic: str | Sequence[str],
*,
type: str | None = None,
palette: str | int | None = None,
direction: int | None = None,
overflow: str | None = None,
name: str | None = None,
breaks: Breaks | None = None,
labels: Labels | None = None,
lablim: int | None = None,
limits: Limits | None = None,
oob: Oob | None = None,
na_value: Color | None = None,
guide: Guide | None = None,
trans: Transform | None = None,
format: str | None = None,
) -> FeatureSpec
Map color aesthetics with a ColorBrewer palette.
Parameters:
-
aesthetic(str or list of str) –The color aesthetic(s), e.g.
"fill"or["color", "fill"]. -
type((seq, div, qual), default:"seq") –Palette family; needed with a palette index.
-
palette(str or int, default:None) –Palette name (e.g.
"Set2","RdBu") or index withintype. Default:Set1for categories,Bluesfor continuous data. -
direction((1, -1), default:1) –-1 reverses the colors.
-
overflow(str, default:None) –How to get more colors than the palette has (
"i","c","g"). -
name(str, default:None) –Legend title.
-
breaks(list or dict, default:None) –Values that get a legend key or 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) –Maximum label length in characters for discrete data; longer labels are cut.
-
limits(list, default:None) –The categories (and their order), or a
[low, high]data range. -
oob((censor, squish), default:"censor") –What continuous data outside
limitsmaps to. Not in lets-plot. -
na_value(str, default:None) –Color drawn for missing data and data outside
limits. -
guide(str or FeatureSpec, default:None) –"legend","colorbar","none", or a guide spec. -
trans(str, default:None) –Transformation of continuous data, e.g.
"log10". -
format(str, default:None) –Label format, e.g.
".1f".labelstake precedence.
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 = {"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", fill="pet"))
>>> plot = plot + geom_point(shape=21, size=6, alpha=0.5)
>>> plot = plot + scale_brewer(["color", "fill"], palette="Dark2")