Skip to content
Related Articles

Related Articles

Improve Article

Get the Hexadecimal Code of the Specified Shade in R Programming – rgb() Function

  • Last Updated : 02 Mar, 2021

rgb() function in R Language is used to specify the shade of the color red, green, and blue between 0 and 1. Further the specified shades of these three basic components will be mixed to form a new shade. The shade of the color red, green, and blue can also be specified between 0 and 255. But there will be an added argument max=255 while using this range. This function returns the corresponding hexadecimal code of the specified shade.
 

Syntax: rgb(a, b, c, max = 255) 
Parameters: 
a: shade of color red 
b: shade of color green 
c: shade of color blue 
max: added argument max=255 
 

Example 1: 
 

Python3




# R program to illustrate
# rgb function
 
# Calling the rgb() function with
# shade of color between 0 to 1
rgb(0, 1, 0.5)
rgb(0.9, 0.7, 0.8)
rgb(0, 0.7, 1)
rgb(0, 0, 0)
rgb(1, 1, 1)

Output: 
 



[1] "#00FF80"
[1] "#E6B3CC"
[1] "#00B3FF"
[1] "#000000"
[1] "#FFFFFF"

Example 2: 
 

Python3




# R program to illustrate
# rgb function
 
# Calling the rgb() function with
# shade of color between 0 and 255
# with added argument max = 255
rgb(0, 0, 0, max = 255)
rgb(5, 7, 60, max = 255)
rgb(255, 255, 255, max = 255)

Output: 
 

[1] "#000000"
[1] "#05073C"
[1] "#FFFFFF"

 




My Personal Notes arrow_drop_up
Recommended Articles
Page :