Open In App

Create a Vector of Colors from a Vector of Gray Levels in R Programming – gray() or grey() Function

Last Updated : 30 Jun, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

gray() or grey() function in R Language is used to create a vector of colors from a vector of gray levels.

Syntax:
gray(level)
or
grey(level)

Parameters:
level: a vector of desired gray levels between 0 and 1; zero indicates “black” and one indicates “white”.

Example 1:




# R program to illustrate
# gray function
  
# Calling the gray() function
gray(0)
gray(1)


Output:

[1] "#000000"
[1] "#FFFFFF"

Example 2:




# R program to illustrate
# gray function
  
# Calling the gray() function
gray(0:9 / 9)


Output:

[1] "#000000" "#1C1C1C" "#393939" "#555555" "#717171" "#8E8E8E" "#AAAAAA"
[8] "#C6C6C6" "#E3E3E3" "#FFFFFF"

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads