do_ColorPalette: Generate color scales based on a value.

View source: R/do_ColorPalette.R

do_ColorPaletteR Documentation

Generate color scales based on a value.

Description

This function is an adaptation of colortools package. As the package was removed from CRAN on 23-06-2022, this utility function came to existence in order to cover the gap. It is, on its basis, an adaptation of the package into a single function. Original code, developed by Gaston Sanchez, can be found in: https://github.com/gastonstat/colortools

Usage

do_ColorPalette(
  colors.use,
  n = 12,
  opposite = FALSE,
  adjacent = FALSE,
  triadic = FALSE,
  split_complementary = FALSE,
  tetradic = FALSE,
  square = FALSE,
  complete_output = FALSE,
  plot = FALSE,
  font.size = 14,
  font.type = "sans"
)

Arguments

colors.use

character | One color upon which generate the color scale. Can be a name or a HEX code.

n

numeric | Number of colors to include in the color wheel. Use it when all other options are FALSE, otherwise, it becomes 12.

opposite

logical | Return the opposing color to the one provided.

adjacent

logical | Return the adjacent colors to the one provided.

triadic

logical | Return the triadic combination of colors to the one provided.

split_complementary

logical | Return the split complementary combination of colors to the one provided.

tetradic

logical | Return the tetradic combination of colors to the one provided.

square

logical | Return the square combination of colors to the one provided.

complete_output

logical | Runs all the previous options and returns all the outputs as a list that contains all color vectors, all plots and a combined plot with everything.

plot

logical | Whether to also return a plot displaying the values instead of a vector with the color.

font.size

numeric | Overall font size of the plot. All plot elements will have a size relationship with this font size.

font.type

character | Base font family for the plot. One of:

  • mono: Mono spaced font.

  • serif: Serif font family.

  • sans: Default font family.

Value

A character vector with the desired color scale.

Examples


  # Check Suggests.
  value <- SCpubr:::check_suggests(function_name = "do_ColorPalette", passive = TRUE)
  
  if (isTRUE(value)){
    # Generate a color wheel based on a single value.
    colors <- SCpubr::do_ColorPalette(colors.use = "steelblue")
    p <- SCpubr::do_ColorPalette(colors.use = "steelblue",
                                 plot = TRUE)
  
    # Generate a pair of opposite colors based on a given one.
    colors <- SCpubr::do_ColorPalette(colors.use = "steelblue",
                                      opposite = TRUE)
    p <- SCpubr::do_ColorPalette(colors.use = "steelblue",
                                 opposite = TRUE,
                                 plot = TRUE)
  
    # Generate a trio of adjacent colors based on a given one.
    colors <- SCpubr::do_ColorPalette(colors.use = "steelblue",
                                      adjacent = TRUE)
    p <- SCpubr::do_ColorPalette(colors.use = "steelblue",
                                 adjacent = TRUE,
                                 plot = TRUE)
  
    # Generate a trio of triadic colors based on a given one.
    colors <- SCpubr::do_ColorPalette(colors.use = "steelblue",
                                      triadic = TRUE)
    p <- SCpubr::do_ColorPalette(colors.use = "steelblue",
                                 triadic = TRUE,
                                 plot = TRUE)
  
    # Generate a trio of split complementary colors based on a given one.
    colors <- SCpubr::do_ColorPalette(colors.use = "steelblue",
                                      split_complementary = TRUE)
    p <- SCpubr::do_ColorPalette(colors.use = "steelblue",
                                 split_complementary = TRUE,
                                 plot = TRUE)
  
    # Generate a group of tetradic colors based on a given one.
    colors <- SCpubr::do_ColorPalette(colors.use = "steelblue",
                                      tetradic = TRUE)
    p <- SCpubr::do_ColorPalette(colors.use = "steelblue",
                                 tetradic = TRUE,
                                 plot = TRUE)
  
    # Generate a group of square colors based on a given one.
    colors <- SCpubr::do_ColorPalette(colors.use = "steelblue",
                                      square = TRUE)
    p <- SCpubr::do_ColorPalette(colors.use = "steelblue",
                                 square = TRUE,
                                 plot = TRUE)
  
    # Retrieve the output of all options.
    out <- SCpubr::do_ColorPalette(colors.use = "steelblue",
                                   complete_output = TRUE)
    ## Retrieve the colors.
    colors <- out$colors
    ## Retrieve the plots.
    plots <- out$plots
    ## Retrieve a combined plot with all the options.
    p <- out$combined_plot
  
  } else if (base::isFALSE(value)){
    message("This function can not be used without its suggested packages.")
    message("Check out which ones are needed using `SCpubr::state_dependencies()`.")
  }


SCpubr documentation built on Oct. 11, 2023, 5:15 p.m.