ac: Adjust color transparency

View source: R/color_fun_2.R

acR Documentation

Adjust color transparency

Description

ac adjusts the transparency of a color or color palette col to an opacity level alpha (in [0, 1]).

Usage

ac(col, alpha = 0.5, use_names = TRUE)

Arguments

col

A (required) color or color palette (as a vector).

alpha

A factor modifying the opacity alpha (as alpha.f in adjustcolor) to a value in [0, 1]. Default: alpha = .50 (i.e., medium opacity).

use_names

A logical value indicating whether color names should be adjusted to include the values of alpha. Default: use_names = TRUE.

Details

ac is mostly a wrapper for adjustcolor of the grDevices package, but allows for more flexible combinations of (multiple) col and alpha values.

The name ac is an abbreviation of "adjust color", but is also a mnemonic aid for providing "air conditioning".

Value

A color vector of the same length as col, transformed by adjustcolor.

See Also

seecol for plotting/seeing color palettes; usecol for using color palettes; simcol for finding similar colors; newpal for defining new color palettes; grepal for finding named colors.

Other color functions: demopal(), grepal(), newpal(), seecol(), shades_of(), simcol(), usecol()

Examples

ac("black")  # using alpha = .5 by default

# multiple colors:
cols <- ac(c("black", "gold", "deepskyblue"), alpha = .50)
seecol(cols, main = "Transparent colors")

# multiple alphas:
blacks <- ac("black", alpha = 5:0/5)
seecol(blacks, main = "One col several alpha values")

bgc <- ac(c("black", "gold"), alpha = 1:6/6)
seecol(bgc, main = "More alpha values than cols")

# Using a color palette:
seecol(ac(pal_unikn_pref, 2/3), main = "Adding color transparency by ac()")

# Color names:
seecol(ac(col = pal_unikn_pref, alpha = c(1/5, 4/5), use_names = TRUE))
seecol(ac(col = pal_unikn_pref, alpha = c(1/5, 4/5), use_names = FALSE))


unikn documentation built on May 29, 2024, 10:41 a.m.