Generate Color Vectors of desired Length in R Programming – rainbow() Function Last Updated : 30 Jun, 2020 Improve Improve Like Article Like Save Share Report 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) 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)) Output: Like Article Suggest improvement Previous Add Leading Zeros to the Elements of a Vector in R Programming - Using paste0() and sprintf() Function Next Convert a Color to its rgb value in R Programming - col2rgb() Function Share your thoughts in the comments Add Your Comment Please Login to comment...