Skip to content
Related Articles

Related Articles

Set or View the Graphics Palette in R Programming – palette() Function

Improve Article
Save Article
  • Last Updated : 07 Dec, 2021
Improve Article
Save Article

In this article, we are going to see how to set or view the Graphic Palette in R Programming Language.

R – palette() Function

palette() function in R Language is used to set or view the Graphics Palette.

Syntax: palette(value)

Parameters: 

value: an optional character vector. 
 

Example 1: 

R




# R program to illustrate
# palette function
 
# Calling the palette() function
# to obtain the current palette
palette()

Output: 

[1] "black"   "red"     "green3"  "blue"    "cyan"    "magenta" "yellow" 
[8] "gray"  

Example 2: 

R




# R program to illustrate
# palette function
 
# Calling the palette() function
# to set 2 extra Graphics Palette
palette(c(palette(), "purple", "brown"))
 
# Viewing the final added Graphics Palette
palette()

Output: 

[1] "black"   "red"     "green3"  "blue"    "cyan"    "magenta" "yellow" 
[8] "gray"    "purple"  "brown"  

Defining your own palettes

Here we will make our own palettes, for this, we will make the vectors along with hex triplets and R color names and then plot the chart with these color names.

R




colors <- c("#A7A7A7",
 "forestgreen",
 "gold")
 
pie(discoveries, col = colors)

Output:


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!