spatstat (version 1.42-1)

colourtools: Convert and Compare Colours in Different Formats

Description

These functions convert between different formats for specifying a colour in R, determine whether colours are equivalent, and convert colour to greyscale.

Usage

col2hex(x)
rgb2hex(v)
paletteindex(x)
samecolour(x,y)
complementarycolour(x)
interp.colours(x, length.out=512)
is.colour(x)
to.grey(x, weights=c(0.299, 0.587, 0.114))
is.grey(x)

Arguments

x,y
Any valid specification for a colour or sequence of colours accepted by col2rgb.
v
A numeric vector of length 3, giving the RGB values (0 to 255) of a single colour, or a 3-column matrix giving the RGB values of several colours.
weights
Numeric vector of length 3 giving relative weights for the red, green, and blue channels respectively.
length.out
Integer. Length of desired sequence.

Value

  • For col2hex, rgb2hex and to.grey, a character vector containing hexadecimal colour codes.

    For paletteindex, an integer vector, possibly containing NA values.

    For samecolour and is.grey, a logical value or logical vector.

Warning

paletteindex("green") returns NA because the green colour in the default palette is called "green3".

Details

is.colour(x) can be applied to any kind of data x and returns TRUE if x can be interpreted as a colour or colours. The remaining functions expect data that can be interpreted as colours. col2hex converts colours specified in any format into their hexadecimal character codes.

rgb2hex converts RGB colour values into their hexadecimal character codes.

paletteindex checks whether the colour or colours specified by x are available in the default palette returned by palette(). If so, it returns the index or indices of the colours in the palette. If not, it returns NA.

samecolour decides whether two colours x and y are equivalent.

is.grey determines whether each entry of x is a greyscale colour, and returns a logical vector. to.grey converts the colour data in x to greyscale colours. Alternatively x can be an object of class "colourmap" and to.grey(x) is the modified colour map.

complementarycolour replaces each colour by its complementary colour in RGB space (the colour obtained by replacing RGB values (r, g, b) by (255-r, 255-g, 255-b)). Alternatively x can be an object of class "colourmap" and complementarycolour(x) is the modified colour map.

interp.colours interpolates between each successive pair of colours in a sequence of colours, to generate a more finely-spaced sequence. It uses linear interpolation in HSV space (with hue represented as a two-dimensional unit vector).

See Also

col2rgb, palette

See also the class of colour map objects: colourmap, interp.colourmap, tweak.colourmap.

Examples

Run this code
samecolour("grey", "gray")
  paletteindex("grey")
  col2hex("orange")
  to.grey("orange")
  complementarycolour("orange")
  is.grey("lightgrey")
  is.grey(8)
  interp.colours(c("orange", "red", "violet"), 5)

Run the code above in your browser using DataCamp Workspace