color_pallette_alpha: Get a pallete of the same color with different transparencies

View source: R/color_pallette_alpha.R

color_pallette_alphaR Documentation

Get a pallete of the same color with different transparencies

Description

Sometimes a variable has more categories than colors in ksnet functions. To deal with this situation this function returns a vector of n colors with progressive transparency.

Usage

color_pallette_alpha(
  color,
  n,
  values = NULL,
  rev = FALSE,
  min_alpha = 0.3,
  max_alpha = 1
)

Arguments

color

a hex color, for example, #00b2a9

n

the number of new colors. Not necessary if values are specified.

values

Optional. Name of the labels.

rev

Optional. Reverse order.

min_alpha

Minimal transparency. Default is 0.3.

max_alpha

Maximum transparency. Default is 1.

Value

A vector of colors with progressive transparency. If values are supplied it is returned a named vector.

Examples

df <- data.frame( x = factor(letters[1:6]),
                  y = round( runif(6),2 ) )

color <- ksnet::paletas_ksnet$classic[5] # "#056F6A"

(col_x <- color_pallette_alpha( color, values = levels(df$x) ))

library(ggplot2)
ggplot( df, aes( x, y, fill = x ) )+
    geom_col()+
    scale_fill_manual( values = col_x )

# reverse color order:
(col_x_rev <- color_pallette_alpha( color, values = levels(df$x),rev = TRUE ))

ggplot( df, aes( x, y, fill = x ) )+
    geom_col()+
    scale_fill_manual( values = col_x_rev )

## Using 'n' parameter
color_pallette_alpha( color, n = 10 )

octmedina/ksnet documentation built on April 18, 2023, 3:34 p.m.