Equivalent RGB color of an object such as a spectrum, wavelength or waveband.
Usage
color_of(x, ...)
# Default S3 method
color_of(x, ...)
# S3 method for class 'numeric'
color_of(x, type = "CMF", chroma.type = type, ...)
# S3 method for class 'list'
color_of(x, short.names = TRUE, type = "CMF", chroma.type = type, ...)
# S3 method for class 'waveband'
color_of(x, short.names = TRUE, type = "CMF", chroma.type = type, ...)
# S3 method for class 'source_spct'
color_of(x, type = "CMF", chroma.type = type, ...)
# S3 method for class 'source_mspct'
color_of(x, ..., idx = "spct.idx")
colour_of(x, ...)
color(x, ...)
fast_color_of_wl(x, type = "CMF", ...)
fast_color_of_wb(x, type = "CMF", ...)
Arguments
- x
an R object.
- ...
ignored (possibly used by derived methods).
- type, chroma.type
character telling whether "CMF", "CC", or "both" should be returned for human vision, or an object of class
chroma_spct
for any other trichromic visual system.- short.names
logical indicating whether to use short or long names for wavebands
- idx
character Name of the column with the names of the members of the collection of spectra.
Value
A color definition in hexadecimal format as a character
string
of 7 characters, "#" followed by the red, blue, and green values in
hexadecimal (scaled to 0 ... 255). In the case of the specialization for
list
, a list of such definitions is returned. In the case of a
collection of spectra, a data.frame
with one column with such
definitions and by default an additional column with names of the spectra
as index. In case of missing input the returned value is NA
.
Methods (by class)
color_of(default)
: Default method (returns always "black").color_of(numeric)
: Method that returns Color definitions corresponding to numeric values representing a wavelengths in nm.color_of(list)
: Method that returns Color of elements in a list.color_of(waveband)
: Color at midpoint of awaveband
object.color_of(source_spct)
:color_of(source_mspct)
:
Note
The specialization of color_of()
for numeric
and function
fast_color_of_wl()
accept both positive and negative values in
x
as long as all values have the same sign. This makes its use in
'ggspectra' simpler as the reverse scale transform changes the sign of the
data. This should be considered a temporary fix.
When x
is a list but not a waveband, if a method color_of
is not available for the class of each element of the list, then
color_of.default
will be called.
Function fast_color_of_wl()
should be used only when high
performance is needed. It speeds up performance by rounding the wavelength
values in the numeric vector passed as argument to x
and then
retrieves the corresponding pre-computed color definitions if type
is either "CMF"
or "CC"
. In other cases it falls-back to
calling color_of.numeric()
. Returned color definitions always have
default names irrespective of names of x
, which is different from
the behavior of color_of()
methods.
Function fast_color_of_wb()
accepts waveband objects and lists of
waveband objects. If all wavebands are narrow, it issues a vectotized
call to fast_color_of_wl()
with a vector of waveband midpoint
wavelengths.
Deprecated
Use of color() is deprecated as this wrapper function may be removed in future versions of the package because of name clashes. Use color_of() instead.
Examples
wavelengths <- c(300, 420, 500, 600, NA) # nanometres
color_of(wavelengths)
#> wl.300.nm.CMF wl.420.nm.CMF wl.500.nm.CMF wl.600.nm.CMF wl.NA.nm.CMF
#> "#000000" "#1B00FF" "#00A92E" "#FF2E00" NA
color_of(waveband(c(300,400)))
#> range.300.400.CMF
#> "#02000F"
color_of(list(blue = waveband(c(400,480)), red = waveband(c(600,700))))
#> blue.CMF red.CMF
#> "#0000FF" "#FF0000"
color_of(numeric())
#> character(0)
color_of(NA_real_)
#> wl.NA.nm.CMF
#> NA
color_of(sun.spct)
#> source.CMF
#> "#544F4B"