R/cb_pal.R

#' Color blind platte
#'
#' @param name
#' @param n
#' @param type
#'
#' @return a palette color
#' @export
cb_pal <- function (name, n, type = c("discrete", "continuous"))
{
  type <- match.arg(type)
  pal <- l_cb_palette[[name]]
  if (is.null(pal))
    stop(paste("Palette not found. Available are", JBUtilities:::names(l_cb_palette), sep = ','))
  if (missing(n)) {
    n <- length(pal)
  }
  if (type == "discrete" && n > length(pal)) {
    stop("Number of requested colors greater than what palette can offer")
  }
  out <- switch(type, continuous = (grDevices::colorRampPalette(pal))(n),
                discrete = pal[1:n])
  structure(out, class = "palette", name = name)
}
JBLecomte/JBUtilities documentation built on March 31, 2021, 7:25 p.m.