addColorMap: Add Basic Color Map to a Plot

Description Usage Arguments Value Examples

View source: R/utility_functions.R

Description

Add Basic Color Map to a Plot

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
addColorMap(
  Z,
  vr = NULL,
  nc = 11,
  clr = NULL,
  z = NULL,
  border = NA,
  add = T,
  return = T,
  ...
)

is.CM(x)

## S3 method for class 'CM'
print(x, digits = 2, ...)

## S3 method for class 'CM'
plot(
  x,
  type = "n",
  xlab = " ",
  ylab = " ",
  xaxt = "n",
  yaxt = "n",
  bty = "n",
  ...
)

Arguments

Z

a matrix with the numeric values to map to a set of colors, or a color map list object of class 'CM' (the output for this function).

vr

an optional vector giving the lower and upper boundaries for to use when mapping the values to colors (defaults to the range for Z).

nc

the number of equally-spaced intervals to use when mapping the values to colors (default approach needs an odd number).

clr

the color values to which values should be mapped.

z

the endpoints for the intervals to use when mapping the values to colors (need to be sequential and equal to the number of colors plus one).

border

controls the border for each color square.

add

logical; if true, adds the color map to an existing plot.

return

logical; if true, returns a color map list object.

...

Additional inputs for the polygon function.

Value

If indicated, returns a color map list object consisting of...

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Generate a correlation matrix
n = 5 # Number of variables
A = matrix( runif(n^2)*2-1, ncol = n )
# Covariance matrix
S = t(A) %*% A
Z = cov2cor( S )

# Create a blank plot
plot( c(0,5), c(0,5), type = 'n', xlab = 'X', ylab = 'Y' )
CM = addColorMap( Z )

# Custom color map
plot( c(0,5), c(0,5), type = 'n', xlab = 'X', ylab = 'Y' )
addColorMap( Z, clr = heat.colors(11), return = F )

# Custom intervals
plot( c(0,5), c(0,5), type = 'n', xlab = 'X', ylab = 'Y' )
z = c( -1, -.75, -.5, 0, .5, .75, 1 ); nc = length(z)
addColorMap( Z, z = z, nc = nc, return = F )

# Create a color map initially, then add to plot
Z = matrix( runif(40), 10, 4 )
CM = addColorMap( Z, clr = heat.colors(11), add = F )
plot( CM )

rettopnivek/utilityf documentation built on March 1, 2021, 7:05 p.m.