How to use Hexadecimal Color Codes In R Language

R




# Set a custom palette using hexadecimal color codes
hex_palette <- c("#FF5733", "#33FF57", "#3366FF", "#FF33DD")
 
# Set the palette
palette(hex_palette)
 
# Create a barplot with the custom palette
barplot(rep(1, 4), col = 1:4, main = "Hex Color Palette", names.arg = 1:4)


Output:

Graphics Palette in R Programming – palette() Function

  1. Define Hexadecimal Color Palette:
    The variable hex_palette is assigned a vector of hexadecimal color codes. Each code represents a distinct color: orange (#FF5733), green (#33FF57), blue (#3366FF), and magenta (#FF33DD).
  2. Set the Palette:
    The palette() function is used to set the color palette for subsequent plots. In this case, it’s set to the custom hexadecimal color palette.
  3. Create a Barplot:
    The barplot() function generates a barplot with bars of equal height (all values in rep(1, 4) are 1). The col parameter specifies the colors for each bar, and the custom palette is applied (col = 1:4). The main parameter sets the main title of the plot to “Hex Color Palette,” and names.arg provides labels for the bars.

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

In R Programming language a graphics palette refers to a set of colors that can be used to enhance the visual appearance of plots and charts. The default graphics palette in R typically consists of a range of colors, but users can customize and define their own palettes based on their preferences or specific needs.

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

Similar Reads

R – palette() Function

The palette() function in base R allows users to set or view the current color palette. It can be used to select or define a custom set of colors....

Using Hexadecimal Color Codes

...

Defining your own palettes

...

Contact Us