View source: R/color_pallette_alpha.R
color_pallette_alpha | R Documentation |
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.
color_pallette_alpha(
color,
n,
values = NULL,
rev = FALSE,
min_alpha = 0.3,
max_alpha = 1
)
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. |
A vector of colors with progressive transparency. If values are supplied it is returned a named vector.
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 )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.