fct_swatches | R Documentation |
Generate colors for a given factor, or something coercible to one.
Useful in conjunction with ggplot2::scale_color_manual()
.
fct_swatches(x, fun = scale_color_tableau, ...)
x |
(factor) or character, convertible to factor |
fun |
(function) like |
... |
further arguments to |
named vector, with colors as values, and levels as names
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.