col2hex(x)
rgb2hex(v, maxColorValue=255)
rgb2hsva(red, green=NULL, blue=NULL, alpha=NULL, maxColorValue=255)
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), transparent=FALSE)
is.grey(x)
to.opaque(x)
to.transparent(x, fraction)
col2rgb
.
rgb
determining the red, green, blue channels and optionally the
alpha (transparency) channel.
Note that red
can also be a matrix with 3 rows
giving the RGB values, or a matrix with 4 rows
giving RGB and alpha values.
v
or red,green,blue,alpha
.
transparent=TRUE
)
or converted to opaque grey values (transparent=FALSE
, the
default).
fraction=1
.
col2hex
and rgb2hex
a character vector containing hexadecimal colour codes.For to.grey
, to.opaque
and to.transparent
,
either a character vector containing hexadecimal colour codes,
or a value identical to the input x
.For rgb2hsva
, a matrix with 3 or 4 rows containing
HSV colour values.For paletteindex
, an integer vector, possibly containing
NA
values.For samecolour
and is.grey
,
a logical value or logical vector.
paletteindex("green")
returns NA
because
the green colour in the default palette is called "green3"
.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. It is a very minor extension to rgb
.
Arguments to rgb2hex
should be similar to
arguments to rgb
.
rgb2hsva
converts RGB colour values into HSV colour values
including the alpha (transparency) channel.
It is an extension of rgb2hsv
.
Arguments to rgb2hsva
should be similar to arguments to
rgb2hsv
.
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.
to.opaque
converts the colours in x
to opaque
(non-transparent) colours, and to.transparent
converts them
to transparent colours with a specified transparency value.
Note that to.transparent(x,1)
is equivalent to to.opaque(x)
.
For to.grey
, to.opaque
and
to.transparent
, if all the data in x
specifies colours from the
standard palette, and if the result would be equivalent to x
,
then the result is identical to x
.
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)
).
The transparency value is not changed.
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).
col2rgb
,
rgb2hsv
,
palette
. See also the class of colour map objects in the spatstat package:
colourmap
,
interp.colourmap
,
tweak.colourmap
.
samecolour("grey", "gray")
paletteindex("grey")
col2hex("orange")
to.grey("orange")
complementarycolour("orange")
is.grey("lightgrey")
is.grey(8)
to.transparent("orange", 0.5)
to.opaque("red")
interp.colours(c("orange", "red", "violet"), 5)
Run the code above in your browser using DataLab