Skip to contents

Multiplies each colour's own alpha channel (1, i.e. fully opaque, for a colour with none already set) by alpha, via grDevices::adjustcolor() – the same mechanism style()'s own color_alpha/fill_alpha properties use internally at draw() time (see ?style). Since an ordinary opaque colour's own alpha is 1, this has the effect of setting the result's alpha to alpha directly for any color with no alpha of its own already.

Usage

color_alpha(color, alpha = 0.5)

Arguments

color

A character vector of colours.

alpha

A numeric vector, each in [0, 1], recycled against color.

Value

A character vector of hex colour strings (including an alpha channel), the same length as the longer of color/alpha.

Examples

color_alpha("black", alpha = 0.5)
#> [1] "#00000080"
color_alpha(palette_manual(index = 1), alpha = c(1, 0.75, 0.5, 0.25, 0.1))
#> [1] "#33658AFF" "#86BBD8BF" "#2F485880" "#F6AE2D40" "#F264191A"