image2: Improved image() function

Description Usage Arguments See Also Examples

View source: R/image2.R

Description

Improved version of the image function in the graphics package. In particular, it displays matrices the way they are shown in the R console, not transposed/rearranged/... For example, a covariance matrix has the diagonal in from top-left to bottom-right as it should be, and not from bottom-left to top-right.

The function make_legend also provides a better color scale legend handling.

Optionally image2 displays a color histogram below the image, which can be used to refine the display of a matrix by trimming outliers (as they can often distort the color representation).

Usage

1
2
3
4
5
6
image2(x = NULL, y = NULL, z = NULL, col = NULL, axes = FALSE, legend = TRUE, 
    xlab = "", ylab = "", zlim = NULL, density = FALSE, max.height = NULL, 
    zlim.label = "color scale", ...)

make_legend(data = NULL, col = NULL, side = 1, zlim = NULL, col.ticks = NULL, 
    cex.axis = 2, max.height = 1, col.label = "")

Arguments

x,y

locations of grid lines at which the values in z are measured. These must be finite, non-missing and in (strictly) ascending order. By default, equally spaced values from 0 to 1 are used. If x is a list, its components x$x and x$y are used for x and y, respectively. If the list has component z this is used for z.

z

a matrix containing the values to be plotted (NAs are allowed). Note that x can be used instead of z for convenience.

col

colors: either a string decribing a pallette from the RColorBrewer package (see also http://colorbrewer2.org/), or a list of colors (see image for suggestions).

axes

a logical value indicating whether both axes should be drawn on the plot.

xlab

a label for the x axis

ylab

a label for the y axis

legend

logical; if TRUE a color legend for will be plotted

zlim

minimum and maximum z values for which colors should be plotted, defaulting to the range of the finite values of z.

zlim.label

character string (default: "color scale") to write next to the color legend

density

logical; if TRUE a color histogram (density) will be plotted. Default: FALSE.

max.height

height of the density plot (typically not modified by user)

...

optional arguments passed to image

data

data for which the legend should be plotted

side

on which side of the plot (1=bottom, 2=left, 3=top, 4=right)

col.ticks

color tick marks

cex.axis

The magnification to be used for axis annotation relative to the current setting of cex.

col.label

same as zlim.label

See Also

image, image.plot

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
## Not run: 
# Correlation matrix
data(iris)  # make sure its from 'datasets' package, not from 'locfit'
image(cor(as.matrix(iris[, names(iris) != "Species"])))

# Correlation matrix has diagonal from top left to bottom right
par(mar = c(1, 3, 1, 2))
image2(cor(as.matrix(iris[, names(iris) != "Species"])), col = "RdBu", axes = FALSE)

## End(Not run)
# Color histogram
nn <- 10
set.seed(nn)
AA <- matrix(sample(c(rnorm(nn^2, -1, 0.1), rexp(nn^2/2, 0.5))), ncol = nn)

image2(AA, col = "Spectral")
image2(y = 1:15 + 2, x = 1:10, AA, col = "Spectral", axes = TRUE)
image2(y = 1:15 + 2, x = 1:10, AA, col = "Spectral", density = TRUE, axes = TRUE)

image2(AA, col = "Spectral", density = TRUE, zlim = c(min(AA), 3))

Example output



LICORS documentation built on May 1, 2019, 10:13 p.m.