R/colwalpha.R

Defines functions colwalpha

Documented in colwalpha

## colwalpha
##
#' Convert a color to use alpha transparency
#'
#' Convert a color to RGB and then to RGB with alpha transparency
#'
#' @param color A character string for a color
#' @param alpha Traparency value (between 0 and 1)
#'
#' @return A character string representing a color
#'
#' @importFrom grDevices rgb col2rgb
#' @export
#' @keywords color
#' @examples
#' colwalpha(c("blue", "red"), 0.5)
colwalpha <-
    function(color, alpha=1)
{
    stopifnot(alpha >=0, alpha <= 1)
    alpha <- alpha * 255

    rgbval <- col2rgb(color)
    rgb(rgbval[1,], rgbval[2,], rgbval[3,], alpha=alpha, maxColorValue=255)
}

Try the broman package in your browser

Any scripts or data that you put into this service are public.

broman documentation built on July 8, 2022, 5:07 p.m.