Open In App

Create a Range of Contiguous Colors Clustered around the Red Spectrum of the RGB Scale in R Programming – heat.colors() Function

Last Updated : 30 Jun, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

heat.colors() function in R Language is used to create a ramp of contiguous colors clustered around the color orange in the red spectrum of the 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: heat.colors(n)

Parameters:
n: desired length of the returned color vector

Example 1:




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


Output:

[1] "#FF0000FF" "#FFFF00FF"
[1] "#FF0000FF" "#FF8000FF" "#FFFF00FF" "#FFFF80FF"
[1] "#FF0000FF" "#FF4000FF" "#FF8000FF" "#FFBF00FF" "#FFFF00FF" "#FFFF80FF"

Example 2:




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


Output:


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads