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

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

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

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

My Personal Notes arrow_drop_up

Recommended Posts:


Check out this Author's contributed articles.

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.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.