A Guide to using Hexadecimals for Color in R

Hexadecimals allow for specificity and flexibility.

Data Scientist Dude
3 min readApr 22, 2023

--

Photo by Alexander Grey on Pexels

In R, hexadecimal (hex) color codes are commonly used to specify colors in graphics and plots. Hexadecimal codes represent colors as a combination of red, green, and blue (RGB) values, where each color is represented by a two-digit hexadecimal number ranging from 00 to FF (0 to 255 in decimal).

Stated another way, we define a color as a 6 hexadecimal digit number of the form #RRGGBB. Where the RR is for red, GG for green and BB for blue and value ranges from 00 to FF.

For example, #FF0000 would be red and #00FF00 would be green similarly, #FFFFFF would be white and #000000 would be black. The color code #0000FF represents pure blue, while##FF0000represents pure red. Here are two examples:

temp <- c(5,7,6,4,8)
barplot(temp, col="#c00000", main="#c00000") # this is the first plot
barplot(temp, col="#AA4371", main="#AA4371") # this is the second plot

--

--

Data Scientist Dude
Data Scientist Dude

Written by Data Scientist Dude

Data Scientist, Linguist and Autodidact - I help people understand and use data models.

No responses yet