trans.color: Make transparent colors.

View source: R/switch.par.r

trans.colorR Documentation

Make transparent colors.

Description

Make transparent colors.

Usage

trans.color(colors, alpha = 0.3, mix = "white", ratio = 0.7)

Arguments

colors

a character vector representing base colors.

alpha

a numeric value between 0 to 1 representing transparency.

mix

a character literal of color represent a color. The base colors are mixed with this color.

ratio

a numeric value between 0 to 1 representing mixture ratio of the base colors and mix color.

Value

a character vector of transparent colors.

Examples

#---------------------------------------------------------------------------
# Example 1: change alpha.
#---------------------------------------------------------------------------
col1 <- "red"
col2 <- trans.color(col1, alpha = 0.1, mix = "white", ratio = 0.7)
col3 <- trans.color(col1, alpha = 0.5, mix = "white", ratio = 0.7)
col4 <- trans.color(col1, alpha = 0.8, mix = "white", ratio = 0.7)
barplot(1:4, col = c(col1, col2, col3, col4))


#---------------------------------------------------------------------------
# Example 2: mix with black.
#---------------------------------------------------------------------------
col1 <- "red"
col2 <- trans.color(col1, alpha = 0.1, mix = "black", ratio = 0.7)
col3 <- trans.color(col1, alpha = 0.5, mix = "black", ratio = 0.7)
col4 <- trans.color(col1, alpha = 0.8, mix = "black", ratio = 0.7)
barplot(1:4, col = c(col1, col2, col3, col4))


#---------------------------------------------------------------------------
# Example 3: change ratio.
#---------------------------------------------------------------------------
col1 <- "red"
col2 <- trans.color(col1, alpha = 0.3, mix = "white", ratio = 0.1)
col3 <- trans.color(col1, alpha = 0.3, mix = "white", ratio = 0.4)
col4 <- trans.color(col1, alpha = 0.3, mix = "white", ratio = 0.9)
barplot(1:4, col = c(col1, col2, col3, col4))

Marchen/partial.plot documentation built on Feb. 13, 2025, 4:18 a.m.