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).
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
## 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))
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(LICORS)
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/LICORS/image2.Rd_%03d_medium.png", width=480, height=480)
> ### Name: image2
> ### Title: Improved image() function
> ### Aliases: image2 make_legend
> ### Keywords: aplot color hplot
>
> ### ** Examples
>
> ## Not run:
> ##D # Correlation matrix
> ##D data(iris) # make sure its from 'datasets' package, not from 'locfit'
> ##D image(cor(as.matrix(iris[, names(iris) != "Species"])))
> ##D
> ##D # Correlation matrix has diagonal from top left to bottom right
> ##D par(mar = c(1, 3, 1, 2))
> ##D 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))
>
>
>
>
>
> dev.off()
null device
1
>