R/set_palettes.R

Defines functions set_palettes

PALS <- c("Accent", "Dark2", "Set1", "Set2", "Set3","Paired", "Pastel1", "Pastel2")

set_palettes <- function(x, cat_cols, ...){
  pals <- PALS[seq_along(cat_cols) %% length(PALS) + 1]
  names(pals) <- cat_cols

  x[cat_cols] <- lapply(cat_cols, function(cat){
    p <- x[[cat]]
    p + ggplot2::scale_fill_brewer(palette = pals[cat])
  })
  x
}

Try the qbinplots package in your browser

Any scripts or data that you put into this service are public.

qbinplots documentation built on April 3, 2025, 6:33 p.m.