We obtain a vector of colors from a vector of gray levels using the gray()
function in the R programming language.
gray(level, alpha = NULL)
The gray()
function takes the following parameter values:
level
(required): This represents the vector which has the desired gray levels between 0
and 1
. It’s worth noting that 0
indicates black
while 1
indicates white
.alpha
(optional): This is an optional value indicating the opacity, if specifed.The gray()
function returns a vector of the color having the same length as the input parameter level
.
# creating a level parametermylevel <- c( 0.1, 0.5, 1.0 )# implementing the gray() functiongray(mylevel, alpha=TRUE)
In the code above, we see the following:
mylevel
representing the level
parameter.gray()
function on the vector object and return the result to the console.