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:
- Define Hexadecimal Color Palette:
The variablehex_palette
is assigned a vector of hexadecimal color codes. Each code represents a distinct color: orange (#FF5733
), green (#33FF57
), blue (#3366FF
), and magenta (#FF33DD
). - Set the Palette:
Thepalette()
function is used to set the color palette for subsequent plots. In this case, it’s set to the custom hexadecimal color palette. - Create a Barplot:
Thebarplot()
function generates a barplot with bars of equal height (all values inrep(1, 4)
are 1). Thecol
parameter specifies the colors for each bar, and the custom palette is applied (col = 1:4
). Themain
parameter sets the main title of the plot to “Hex Color Palette,” andnames.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.
Contact Us