Permutation Image Plot
Provides methods for plotting image plots for
matrix and dist objects given a permutation.
By default, no permutation is performed.
This plot can also
be used as a more versatile replacement of image plot
in graphics based on grid.
pimage(x, order = NULL, col = NULL, main ="", xlab = "", ylab = "", axes = "auto", zlim=NULL, key=TRUE, key.lab="", symkey=TRUE, upper.tri = TRUE, lower.tri = TRUE, prop = NULL, ..., newpage=TRUE, pop=TRUE, gp=NULL)
x |
a matrix or an object of class |
order |
an object of class |
col |
a list of colors used. If |
main |
plot title. |
xlab, ylab |
labels for the x and y axes. |
axes |
a character string indicating if axes labels (column and row
names of |
zlim |
vector with two elements giving the range (min, max) for representing the values in the matrix. |
key |
logical; add a color key? No key is available for logical matrices. |
key.lab |
string plotted next to the color key. |
symkey |
logical; if |
upper.tri, lower.tri |
a logical indicating whether to show the upper or lower triangle of the distance matrix. |
prop |
logical; draw the cells in the image proportional (defaults to
|
... |
further arguments passed on to |
newpage, pop |
two logical. Start plot on a new page and pop the viewports after plotting (see grid). |
gp |
a |
Plots a matrix in its original row and column orientation. This means, in a plot the columns become the x-coordinates and the reversed rows the y-coordinates.
If x is of class dist it is converted to full-storage
representation before plotting.
The viewports used for plotting are called: "plot", "image"
and "colorkey".
Note: Since pimage uses grid, it should not be mixed with base R primitive plotting
functions, but the appropriate functions in grid-package.
Christian Buchta and Michael Hahsler
grid-package,
seriate,
hmap,
dissplot and
image.
x <- matrix(sample(c(FALSE, TRUE), 300, rep=TRUE), ncol=10,
dimnames = list(1:30, LETTERS[1:10]))
## matrix (large values are dark/black)
pimage(x, main = "Random data", key = FALSE)
## plot seriated matrix (use red, proportional display and plot all axes)
pimage(x, seriate(x), col = c("white", "red"),
prop = TRUE, axes="both", main = "Reordered data", key = FALSE)
## show correlation (for neg. values a diverging color scheme is
## used automatically)
pimage(cor(x), prop=TRUE)
## distances (note that low distances are represented dark!)
d <- dist(x, method = "binary")
pimage(d, upper.tri = FALSE, main = "Distances")
pimage(d, seriate(d), upper.tri = FALSE, main = "Distances", axes = "both")
## add to the plot using functions in package grid
library("grid")
pimage(x, pop = FALSE) ### pop = FALSE allows us to manipulate viewports
downViewport(name = "image")
## highlight cell 7/5 with a red arrow
grid.lines(x = c(5, 7), y = c(3, 5), arrow = arrow(),
default.units = "native", gp = gpar(col="red", lwd = 3))
## add a red box around rows 15 and 16
grid.rect(x = 0.5, y = 15.5, width = ncol(x), height = 2,
just = "left",
default.units = "native", gp = gpar(col="red", lwd = 3, fill = NA))
## remove the viewports
popViewport(0)
## put several pimages on a page (uses viewports and newpage = FALSE)
library(grid)
grid.newpage()
pushViewport(viewport(layout=grid.layout(nrow = 1, ncol = 2)))
pushViewport(viewport(layout.pos.row = 1, layout.pos.col = 1))
## seriate matrix
o <- seriate(x)
pimage(x, o, main = "Random data", prop = TRUE, axes = "both", key = FALSE,
newpage = FALSE)
upViewport(1)
pushViewport(viewport(layout.pos.row = 1, layout.pos.col = 2))
## add the reordered disimilarity matrix for rowa
pimage(d, o[[1]], upper.tri = FALSE, main = "Distances", axes = "both",
key = FALSE, newpage = FALSE)
upViewport(1)
popViewport(0)Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.