Description Usage Arguments Value Examples
View source: R/utility_functions.R
Add Basic Color Map to a Plot
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 |
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
|
If indicated, returns a color map list object consisting of...
Z: the original matrix of data.
cmap: a list with z, the endpoints of the intervals used to map colors to values, and clr, the set of colors to which values were assigned.
x: a matrix with the x-axis values for
each color cell for the polygon
function.
y: a matrix with the y-axis values for
each color cell for the polygon
function.
clr: a list giving 1) the color for each cell in the map, 2) the x-axis position, 3) the y-axis position, and 4) the associated value.
xl: the lower and upper intervals for the width of the color map.
yl; the lower and upper intervals for the height of the color map.
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 )
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.