fct_swatches: fct_swatches

fct_swatchesR Documentation

fct_swatches

Description

Generate colors for a given factor, or something coercible to one. Useful in conjunction with ggplot2::scale_color_manual().

Usage

fct_swatches(x, fun = scale_color_tableau, ...)

Arguments

x

(factor) or character, convertible to factor

fun

(function) like ggplot2::scale_color_discrete()

...

further arguments to fun

Value

named vector, with colors as values, and levels as names

Examples

df <- mutate(mtcars, carb = fct_other(factor(carb), keep = 1:2))
p <- ggplot(df, aes(wt, mpg)) + geom_point(aes(color = carb))
swatches <- replace(fct_swatches(p$data$carb), "Other", gray(0.5))
p + scale_color_manual(values = swatches)

BAAQMD/ggtools documentation built on Feb. 8, 2023, 6:22 p.m.