max
) of the red, green and blue
primaries. The colour specification refers to the
standard sRGB colorspace (IEC standard 61966). An alpha transparency value can also be specified (as an opacity, so
0
means fully transparent and max
means opaque). If
alpha
is not specified, an opaque colour is generated.
The names
argument may be used to provide names for the
colors.
The values returned by these functions can be used with a
col=
specification in graphics functions or in par
.
rgb(red, green, blue, alpha, names = NULL, maxColorValue = 1)
maxColorValue
. When this is 255
, the
red
, blue
, green
, and alpha
values are coerced to integers in 0:255
and the result is
computed most efficiently."#"
followed by the red, blue, green and optionally alpha values in
hexadecimal (after rescaling to 0 ... 255
). The optional alpha
values range from 0
(fully transparent) to 255
(opaque).R does not use premultiplied alpha.
red
, and leaving blue
and green
missing.
In this case the first three columns of red
are taken to be
the red
, green
and blue
values. Semi-transparent colors (0 < alpha < 1
) are supported only on
some devices: at the time of writing on the pdf
,
windows
, quartz
and X11(type = "cairo")
devices and
associated bitmap devices (jpeg
, png
, bmp
,
tiff
and bitmap
). They are supported by several
third-party devices such as those in packages \href{https://CRAN.R-project.org/package=#1}{\pkg{#1}}CairoCairo,
\href{https://CRAN.R-project.org/package=#1}{\pkg{#1}}cairoDevicecairoDevice and \href{https://CRAN.R-project.org/package=#1}{\pkg{#1}}JavaGDJavaGD. Only some of these
devices support semi-transparent backgrounds.
Most other graphics devices plot semi-transparent colors as fully
transparent, usually with a warning when first encountered.
NA
values are not allowed for any of red
, blue
,
green
or alpha
.
col2rgb
for translating R colors to RGB vectors;
rainbow
, hsv
, hcl
,
gray
.
rgb(0, 1, 0)
rgb((0:15)/15, green = 0, blue = 0, names = paste("red", 0:15, sep = "."))
rgb(0, 0:12, 0, max = 255) # integer input
ramp <- colorRamp(c("red", "white"))
rgb( ramp(seq(0, 1, length = 5)), max = 255)
Run the code above in your browser using DataLab