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:
# R program to illustrate # topo.colors function # Calling topo.colors() function topo.colors( 2 ) topo.colors( 4 ) topo.colors( 6 ) |
chevron_right
filter_none
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 )) |
chevron_right
filter_none
Output: