MakeColors | R Documentation |
MakeColors builds a vector of colors that represent numerical values or group memberships or a combination of both (see the Details section).
MakeColors(
v,
thresholds = NULL,
colors = NULL,
range = NULL,
number = NULL,
below = "white",
above = "white",
na = NA,
levels = 256,
name = "",
parameters = NULL,
alpha = 1,
override = TRUE,
grp = NULL,
grp.prm = NULL
)
v |
vector of numeric values. |
thresholds |
numeric vector defining the boundaries for each range of values to be
mapped into a specific color interval. When unspecified, thresholds are
automatically set according to the |
colors |
color vector providing the colors representing each threshold value (default = rainbow). |
range |
range of the numeric values to be represented
(default = |
number |
the number of color intervals, used only if thresholds and colors
are unspecified (default = |
below |
color used for all values below the minimum threshold
(defaut = |
above |
color used for all values above the maximum threshold
(defaut = |
na |
color used for missing ( |
levels |
integer vector controlling the number of color levels generated in each
color interval (default = |
name |
recall a predefined set of color mapping parameters. |
parameters |
list of color mapping parameters defined by DefineColorMap. |
alpha |
transparency (numeric value(s) between |
override |
logical determining if the transparency of below and above colors should override the provided alpha value(s) (default = TRUE, yes). |
grp |
group memberships (default = none). See GroupIndex for documentation on how to specify group memberships. |
grp.prm |
data.frame of group representation parameters defined by DefineGroupStyles. |
The color representation of numerical values is generated by applying piecewise color mapping to these values, with precise control of the underlying color scale. Group coloring consist in using specific colors to represent predefined group memberships. See DefineGroupStyles for the documentation on group representation parameters and GroupIndex for documentation on how to specify group memberships in a finite set of elements. Group coloring can be used exclusively by leaving all the piecewise color mapping parameters unspecified (which implies not providing any values for the first argument of this function).
MakeColors
returns a character vector of RGBA colors in hexadecimal.
ColorLegend, DefineColorMap, DefineGroupStyles, colorize
# Radial color gradients with two normally distributed random variables
layout(matrix(1:4, 2, 2, byrow = TRUE))
x <- rnorm(2000)
y <- rnorm(2000)
z <- sqrt(x^2 + y^2)
a <- atan2(y, x) + pi / 2
alpha <- ifelse(cos(8 * a) > 0, 0, 1)
clr.prm <- DefineColorMap(
c(0, 2), c("black", "white"), above = "red", range = c(0, 2.3)
)
clr <- MakeColors(z, parameters = clr.prm, alpha = alpha, override = FALSE)
plot(x, y, xlim = c(-5, 5), ylim = c(-5, 5), pch = 20, col = clr)
ColorLegend("topleft", parameters = clr.prm, cex = 0.8)
clr.prm <- DefineColorMap(
seq(0, 2, 0.5), c("black", "lightgrey"), above = "red", range = c(0, 2.3)
)
clr <- MakeColors(z, parameters = clr.prm)
plot(x, y, xlim = c(-5, 5), ylim = c(-5, 5), pch = 20, col = clr)
ColorLegend("topleft", parameters = clr.prm, cex = 0.8)
clr.prm <- DefineColorMap(
thresholds = c(0, 2), colors = c("black", "lightgrey"), above = "red",
range = c(0, 2.3), levels = 4
)
clr <- MakeColors(z, parameters = clr.prm)
plot(x, y, xlim = c(-5, 5), ylim = c(-5, 5), pch = 20, col = clr)
ColorLegend(
"topleft", parameters = clr.prm,
ticks = seq(0, 2, length.out = 5),
cex = 0.8
)
# Use of a log scale in the color space
x <- runif(2000, -3, 3)
y <- runif(2000, -3, 3)
z <- 1 / sqrt(x^2 + y^2) # color mapped values
q <- 1/c(2, 1, 0.5) # thresholds
r <- exp(log(1/c(2, 0.5)) + c(-0.25, 0.25)) # range
clr.prm <- DefineColorMap(
q, c(grey(1:0/2), "red"), above = "lightgrey", below = "lightgrey",
range = r
)
clr <- MakeColors(z, parameters = clr.prm)
plot(x, y, xlim = c(-5, 5), ylim = c(-5, 5), pch = 20, col = clr)
ColorLegend("topleft", parameters = clr.prm, cex = 0.8, log = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.