Open In App
Related Articles

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

Improve Article
Improve
Save Article
Save
Like Article
Like

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

Parameters:
n: desired length of the returned color vector

Example 1:




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


Output:

[1] "#00A600FF" "#F2F2F2FF"
[1] "#00A600FF" "#E6E600FF" "#ECB176FF" "#F2F2F2FF"
[1] "#00A600FF" "#63C600FF" "#E6E600FF" "#EAB64EFF" "#EEB99FFF" "#F2F2F2FF"

Example 2:




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


Output:
terrain.colors()

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 01 Jul, 2020
Like Article
Save Article
Previous
Next
Similar Reads