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

colors() 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 colour 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:

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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

chevron_right


Output:

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

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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

chevron_right


Output:

[1] "#000000"
[1] "#05073C"
[1] "#FFFFFF"
My Personal Notes arrow_drop_up

Recommended Posts:


Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



Improved By : Akanksha_Rai

Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.