R/expand_palette.R

Defines functions make_pal_expand_lighter

#' @export
make_pal_expand_lighter <- function(colors) {
  f <- function(n) {}
  body(f) <- bquote(pal_expand_lighter(.(colors), n))
  f
}

#' @importFrom colorspace lighten
pal_expand_lighter <- function(colors, n) {
  if (n <= length(colors)) return(colors[1:n])
  n_added_palettes <- n %/% length(colors)
  lighten_amts <- (0:n_added_palettes) / (n_added_palettes / 0.8)
  lightened_colors <- lapply(lighten_amts, colorspace::lighten, col = colors)
  c(do.call(rbind, lightened_colors))[1:n]
}
dgkf/ggtheme documentation built on Jan. 26, 2020, 12:56 a.m.