Returns a named character vector of hex color codes from an Insper palette. When printed interactively, displays a visual color swatch. The result behaves as a plain character vector and can be used directly anywhere colors are accepted.
Arguments
- palette
Character. Palette name. Use
show_insper_palettesto see all options.- n
Integer or NULL. Number of colors to return. If NULL (default), returns all colors in the palette. If
nexceeds the palette size, colors are recycled with a warning.- reverse
Logical. If TRUE, reverses the color order. Default FALSE.
Value
An object of class insper_palette (a named character vector of
hex codes). Printing displays a visual swatch. Use as.character() to
strip the class if needed.
Details
Available palettes by type:
Qualitative: main, bright, contrast, categorical, categorical_ito, categorical_tab, categorical_set
Sequential: reds, oranges, teals, grays
Diverging: red_teal, red_teal_ext, diverging
Accent: accent_red, accent_teal
Examples
# Get all colors from a palette
insper_palette("main")
# Subset to n colors
insper_palette("reds", n = 3)
# Reverse order
insper_palette("red_teal", reverse = TRUE)
# Use directly in a plot
library(ggplot2)
ggplot(mtcars, aes(wt, mpg)) +
geom_point(color = insper_palette("reds", n = 1))
# Use in manual scales
ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) +
geom_point() +
scale_color_manual(values = insper_palette("main", n = 3))
