Open In App

Generate a Vector of specified length with each element as a unique color on RGB scale in R Language – topo.colors() Function

Last Updated : 01 Jul, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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

Parameters:
n: desired length of the returned color vector

Example 1:




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


Output:

[1] "#4C00FFFF" "#00E5FFFF"
[1] "#4C00FFFF" "#00E5FFFF" "#00FF4DFF" "#FFFF00FF"
[1] "#4C00FFFF" "#00E5FFFF" "#00FF4DFF" "#E6FF00FF" "#FFFF00FF" "#FFE0B3FF"

Example 2:




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


Output:


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads