What is the colors() function in R?

Overview

The colors() function in R is used to return all the built-in color names in R.

Syntax

colors(distinct = FALSE)
colours(distinct = FALSE)
Syntax for the "colors()" function
Note: The colors() function can also be interchanged with the colours() function.

Parameters

The colors() function takes a single parameter value, distinct, which takes a Boolean value of either TRUE or FALSE.

Return value

The colors() function returns a character vector that contains all the built-in color names in R.

Code examples

# Getting all the built-in colors in R
colors(distinct=FALSE)

# Getting all the built-in distinc colors in R
colors(distinct=TRUE)

Code explanation

The distinct parameter indicates whether the colors returned are distinct or not, for example, "snow" and "snow1" are effectively the same point in the (0:255)3(0:255)^3 RGB space. Hence, by default, the value is FALSE.

Free Resources