Search code examples
rplotcolors

base R: possible to redefine a color name or define a new one?


In a base R plot it is possible to specify a color as a number (which refers to the currently defined palette()), or a hex-string, or a name such as 'red', among those listed in colors().

Q1: Is it possible in base R to redefine some of the names in colors() to different hex values, for instance to make 'red' correspond to #EE6677? So that a call like

plot(x = 1:2, y = 1:2, col = 'red')

would yield the same output as

plot(x = 1:2, y = 1:2, col = '#EE6677')

(I'm very aware that this could break many things!)

Q2: Alternatively, is it possible to add and define new color names, for instance a string 'myred' that would correspond to #EE6677? So that a call like

plot(x = 1:2, y = 1:2, col = 'myred')

would yield the same output as

plot(x = 1:2, y = 1:2, col = '#EE6677')

(Note that what I'd like to achieve is different from what can be done by this answer to another question.)

Thank you!


Solution

  • No. This is translated by col2rgb() (e.g. col2rgb("lavender")), and the color table is hard-coded here.

    For what it's worth I think this is the same as the X11 color name list, first defined in 1985.