** 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:**

`# R program to illustrate ` `# rainbow function ` ` ` `# Calling rainbow() function ` `rainbow(` `2` `) ` `rainbow(` `4` `) ` `rainbow(` `6` `) ` |

*chevron_right*

*filter_none*

**Output:**

[1] "#FF0000FF" "#00FFFFFF" [1] "#FF0000FF" "#80FF00FF" "#00FFFFFF" "#8000FFFF" [1] "#FF0000FF" "#FFFF00FF" "#00FF00FF" "#00FFFFFF" "#0000FFFF" "#FF00FFFF"

**Example 2:**

`# R program to illustrate ` `# rainbow function ` ` ` `# Using rainbow() function to ` `# plot 6 different color ` `barplot(` `1` `:` `6` `, col ` `=` `rainbow(` `6` `)) ` |

*chevron_right*

*filter_none*

**Output:**

## Recommended Posts:

- Getting and Setting Length of the Vectors in R Programming - length() Function
- Generate a Vector of specified length with each element as a unique color on RGB scale in R Language - topo.colors() Function
- Generate a Vector of specified length with each element as a unique color on RB scale in RGB spectrum in R Language - cm.colors() Function
- Generate a Vector of specified length with each element as a unique color on RG scale in RGB spectrum in R Language - terrain.colors() Function
- Create a Data Frame of all the Combinations of Vectors passed as Argument in R Programming - expand.grid() Function
- Compute the beta value of Non-Negative Numeric Vectors in R Programming - beta() Function
- Compute the Covariance between Two Vectors in R Programming - cov() Function
- Compute the Correlation Coefficient Value between Two Vectors in R Programming - cor() Function
- Generating sequenced Vectors in R Programming - sequence() Function
- Find positions of Matching Elements between Vectors in R Programming - match() Function
- Generate a Sequence of Length of the passed Argument in R Programming - seq_along() Function
- Creating a Data Frame from Vectors in R Programming
- Compute the Parallel Minima and Maxima between Vectors in R Programming - pmin() and pmax() Functions
- Assigning Vectors in R Programming
- Types of Vectors in R Programming
- Append Operation on Vectors in R Programming
- Dot Product of Vectors in R Programming
- Cross Product of Vectors in R Programming
- Combine Vectors, Matrix or Data Frames by Columns in R Language - cbind() Function
- Combine Vectors, Matrix or Data Frames by Rows in R Language - rbind() Function

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.