Modify the Table of Named Colors

DESCRIPTION:

Add new colors to the table of named colors used when specifying a color as a string in graphics functions.

USAGE:

add.color.values(x, new=F, overwrite=F, warn=T)

REQUIRED ARGUMENTS:

x
Named character vector of RGB values such as "#FF0000" or "#FF000080". The element names will be used as the color names. Names must start with a letter. See the help for details on the format.

OPTIONAL ARGUMENTS:

new
Logical indicating whether to discard the previous table of colors. If T, the previous colors will be discarded. If F, the specified colors will be added to the current table of colors.
overwrite
Logical indicating how to handle name conflicts when new = F. If T, the new values will be used. If F, the previous values will be retained.
warn
Logical indicating whether to generate a warning when name conflicts lead to new color values being discarded when new = F and overwrite = F. If T, a warning is generated for each new value that is ignored.

VALUE:

Invisibly returns a named character vector of the colors before changes are made.

SIDE EFFECTS:

Changes the table of named colors used to convert strings such as "red" to RGB hex strings.

DETAILS:

The add.color.values() function modifies the color name mapping. It takes a named character vector of RGB values in the form "#FF0000" or "#FF000080". The names are used as the color names, and the values as the RGB values.

Additional arguments determine whether to discard the current table of names, and whether the old or new color definition should be used when a specified name is already in the table.

S-PLUS includes some preconstructed sets of colors that can be used with add.color.values() to get commonly used color mappings.

SEE ALSO:

, , , .

EXAMPLES:

# Add new colors "upsbrown" and "rojo"
add.color.values(c(upsbrown="#964B00", rojo="#FF0000"))

# Use the CSS colors as the only named colors
add.color.values(css.colors, new = T)

# Use the X11 colors when no matching CSS colors
add.color.values(x11.colors)

# Use the X11 colors when no matching CSS colors, don't warn of name conflicts
add.color.values(x11.colors, warn = F)

# Use the X11 colors, use X11 value when name conflicts
add.color.values(x11.colors, overwrite = T)