Helper function to quickly apply a palette to common plotting functions

palette_color(name, n = NULL, reverse = FALSE)

Arguments

name

Character name of the palette

n

Number of colors needed (typically matches the number of groups)

reverse

Logical. Should the palette be reversed?

Value

A function that can be used with the col parameter in plotting functions

Examples

if (FALSE) { # \dontrun{
# For base R plots
plot(mpg ~ disp, data = mtcars, col = palette_color("sunset")(factor(mtcars$cyl)))

# For ggplot2 (after setting up scale_color_palette or scale_fill_palette)
library(ggplot2)
ggplot(mtcars, aes(mpg, disp, color = factor(cyl))) +
  geom_point() +
  scale_color_manual(values = palette_color("sunset")(3))
} # }