Open In App

Create a Range of Colors between the Specified Colors in R Programming - colorRampPalette() Function

Last Updated : 15 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report
colorRampPalette() function in R Language is used to create a color range between two colors specified as arguments to the function. This function is used to specify the starting and ending color of the range.
Syntax: colorRampPalette(c("color1", "color2")) Parameters: color1, color2: starting and ending colors of the range. Returns: color range between specified colors
Example: r
# R program to create a color range

# Apply colorRampPalette Function
fun_color_range <- colorRampPalette(c("Green", "darkgreen"))   
my_colors <- fun_color_range(100)  

# Plotting a graph
plot(1:100, pch = 20, col = my_colors)
Output: Example 2: r
# R program to create a color range

# Apply colorRampPalette Function
fun_color_range <- colorRampPalette(c("blue", "orange"))   
my_colors <- fun_color_range(100)  

# Plotting a graph
plot(1:100, pch = 40, col = my_colors)
Output :

Article Tags :

Similar Reads