Generate Color Vectors of desired Length in R Programming – rainbow() Function
Last Updated :
30 Jun, 2020
rainbow()
function in R Language is a built in color palettes which can be used to quickly generate color vectors of desired length taken as the parameter and returns the hexadecimal code of the colours available. This hexadecimal code is of eight digits. This is because the last two digits specify the level of transparency (where FF is opaque and 00 is transparent).
Syntax: rainbow(n)
Parameters:
n: desired length of the returned color vector
Example 1:
rainbow( 2 )
rainbow( 4 )
rainbow( 6 )
|
Output:
[1] "#FF0000FF" "#00FFFFFF"
[1] "#FF0000FF" "#80FF00FF" "#00FFFFFF" "#8000FFFF"
[1] "#FF0000FF" "#FFFF00FF" "#00FF00FF" "#00FFFFFF" "#0000FFFF" "#FF00FFFF"
Example 2:
barplot( 1 : 6 , col = rainbow( 6 ))
|
Output:
Share your thoughts in the comments
Please Login to comment...