Skip to content
Related Articles

Related Articles

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

Improve Article
Save Article
  • Last Updated : 01 Jul, 2020
Improve Article
Save Article

cm.colors() function in R Language is used to generate a Vector of specified length with each element as a unique color on RB scale in RGB spectrum. This function also 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: cm.colors(n)

Parameters:
n: desired length of the returned color vector

Example 1:




# R program to illustrate
# cm.colors function
  
# Calling cm.colors() function
cm.colors(2)
cm.colors(4)
cm.colors(6)

Output:

[1] "#80FFFFFF" "#FF80FFFF"
[1] "#80FFFFFF" "#BFFFFFFF" "#FFBFFFFF" "#FF80FFFF"
[1] "#80FFFFFF" "#AAFFFFFF" "#D5FFFFFF" "#FFD5FFFF" "#FFAAFFFF" "#FF80FFFF"

Example 2:




# R program to illustrate
# cm.colors function
  
# Using cm.colors() function to
# plot 6 different color
barplot(1:6, col = cm.colors(6))

Output:
cm.colors()

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!