R/which_palette_type.R

Defines functions palette_mapping palette_types which_palette_type

#' @export
which_palette_type <- function(v, type = NULL){
  if(!is.null(type)){
    if(!type %in% palette_types()){
      stop("Palette type must be one of: ",
        dstools::collapse(palette_types()))
    } else {
      return(type)
    }
  }
  if(is.numeric(v)){
    return("sequential")
  }
  if(is.factor(v))
    v <- as.character(v)
  "categorical"
}

palette_types <- function(){
  c("categorical", "diverging", "sequential")
}


palette_mapping <- function(){
  c("continuous", "discrete")
}
jpmarindiaz/paletero documentation built on March 11, 2024, 6:42 a.m.