rgb | R Documentation |
Create a vector of colors from red, green, and blue. This is a drop-in replacement for the rgb
function, included with R in package grDevices
.
rgb( red = 0, green = 0, blue = 0, alpha = NULL, names = NULL, maxColorValue = 1 ) rgba(red = 0, green = 0, blue = 0, alpha = 1)
red, green, blue |
color channels, numbers in |
alpha |
transparency, number in |
names |
character vector. The names for the resulting vector. |
maxColorValue |
number giving the maximum of the color values range, typically 1 or 255. |
The first argument can also be a data.frame or a matrix. In that case, its columns are considered as the color components, taken in order, and the other color components arguments are ignored.
When separate arguments are used for the color components and are vectors, values in shorter arguments are recycled to match the length of the longest argument. If the lengths are not compatible, an error is output.
rgba
is a variant which forces maxColorValue
to be 1 and requires four color components, including alphaallows to specify an alpha value as a color component (i.e. as the fourth column of the first argument when this argument is a matrix/data.frame).
RGB is how colors are displayed on a computer screen. However, this is not how colors are perceived by the human eye/brain. Other color spaces such as HCL and L*a*b* make it easier to create color palettes that are appropriate for human perception.
A vector of colors specified as hex codes
parse_color
for the general function to parse colors in various specifications (which this function calls internally) and convert_color
to convert parsed colors to another model.
Other color specifications:
cmyk()
,
css()
,
hcl()
,
hex()
,
hsi()
,
hsl()
,
hsv()
,
lab()
,
parse_color()
,
ryb()
,
temperature()
,
wavelength()
rgb() rgb(1, 0, 0) rgb(255, 0, 0, maxColorValue=255) rgb(data.frame(c(0.2, 0.5), c(0.5,0.5), c(0.6, 0.4))) rgb(matrix(c(0.2, 0.5, 0.5, 0.5, 0.6, 0.4), ncol=3)) rgb(c(0.2, 0.5), 0, 0) red <- rgb(1, 0, 0) transparent_red <- rgb(1, 0, 0, alpha=0.7) show_col(c(red, transparent_red)) # Color ramps ramp <- seq(0, 1, length.out=10) rgb(red=ramp, green=0, blue=0, names=paste("red", 1:10, sep=".")) show_col( rgb(r=ramp), rgb(g=ramp), rgb(b=ramp) )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.