What is the gray() function in R?
Overview
We obtain a vector of colors from a vector of gray levels using the gray() function in the R programming language.
Syntax
gray(level, alpha = NULL)
Parameter value
The gray() function takes the following parameter values:
level(required): This represents the vector which has the desired gray levels between0and1. It’s worth noting that0indicatesblackwhile1indicateswhite.alpha(optional): This is an optional value indicating the opacity, if specifed.
Return value
The gray() function returns a vector of the color having the same length as the input parameter level.
Example
# creating a level parametermylevel <- c( 0.1, 0.5, 1.0 )# implementing the gray() functiongray(mylevel, alpha=TRUE)
Explanation
In the code above, we see the following:
- Line 2: We create a vector object
mylevelrepresenting thelevelparameter. - Line 5: We apply the
gray()function on the vector object and return the result to the console.