Learn R Programming

EpiModel (version 2.0.1)

transco: Obtain Transparent Colors

Description

Returns an RGB transparent color from any standard R color.

Usage

transco(col, alpha = 1, invisible = FALSE)

Arguments

col

Vector consisting of colors, of any of the three kinds of R color specifications (named, hexadecimal, or integer; see col2rgb).

alpha

Vector of transparency levels, where 0 is transparent and 1 is opaque.

invisible

Supresses printing of the RGB color.

Value

A vector of length equal to the input col vector or the alpha, vector, if one or the other is of length greater than 1, containing the transformed color values in hexidemical format.

Details

The purpose of this function is to facilitate color transparency, which is used widely in EpiModel plots. This is an internal function that is not ordinarily called by the end-user. This function allows that one of col or alpha may be of length greater than 1.

See Also

rgb, col2rgb

Examples

Run this code
# NOT RUN {
## Example 1: Bubble plot with multiple length color vector
n <- 25
x <- sort(sample(1:200, n))
y <- 10 + 2*x + rnorm(n, 0, 10)
z <- rpois(n, 10)
cols <- transco(c("steelblue", "black"), 0.5)
par(mar=c(2, 2, 1, 1))
plot(x, y, cex = z/4, pch = 21, col = "black",
     bg = cols[1], lwd = 1.2, axes = FALSE,
     ylim = c(0, 500), xlim = c(0, 250),
     yaxs = "r", xaxs = "r")
axis(2, seq(0, 500, 100), col = "white", las = 2,
    cex.axis = 0.9, mgp = c(2, 0.5, 0))
axis(1, seq(0, 250, 50), cex.axis = 0.9,
     mgp = c(2, 0.5, 0))
abline(h = seq(100, 500, 100), col = cols[2])

## Example 2: Network plot with multiple length alpha vector
net <- network_initialize(n = 500)
vcol <- transco("firebrick",
                alpha = seq(0, 1, length = network.size(net)))
par(mar = c(0, 0, 0, 0))
plot(net, vertex.col = vcol, vertex.border = "grey70",
     vertex.cex = 1.5, edge.col = "grey50")

# }

Run the code above in your browser using DataLab