[R] question on layout and image.plot

Ranjan Maitra maitra at iastate.edu
Sat Sep 15 01:00:45 CEST 2007


Dear colleagues,

I have struggled for the past couple of days with the following layout of plots. First, for something that finally works (and I understand it also, or so I think!):

A B x 

where A and B are 4x4 matrices of images, x is the common legend for A and B.

The following does what I want (note that the images are nonsensical realizations from N(0, 1) in this rendering so that it is possible for people to try it out):



library(fields)


mat <- matrix(1:16, ncol = 4, nrow = 4, by = T)
mat2 <- cbind(mat, rep(17, nrow(mat)), mat + 17, rep(34, nrow(mat)),
rep(35, nrow(mat)))
layout(mat2, heights = rep(8, 4), widths = c(rep(8, 4), 1, rep(8,
4), 3, 1), respect = F)   

par(mar = c(0, 0, 0, 0))

for (i in 1:16) image(matrix(rnorm(64^2), ncol = 64), col =
 tim.colors(64), axes = F)

frame()

for (i in 1:16) image(matrix(rnorm(64^2), ncol = 64), col =
 tim.colors(64), axes = F)

par(oma = c(0, 0, 0, 4))
par(mar = c(0, 0, 0, 0))

image.plot( zlim = c(-3, 3) , cex = 0.7, lwd = 0.5, legend.only=TRUE,
legend.width = 15, legend.shrink = 0.75)






The above works. But now, I want something that is of the format:

A x B x

where A and B are 4x4 matrices of images, x are the corresponding legends for A and B.

So, I tried the following:


library(fields)


mat <- matrix(1:16, ncol = 4, nrow = 4, by = T)
mat2 <- cbind(mat, rep(17, nrow(mat)), rep(18, nrow(mat)), mat + 18,
rep(35, nrow(mat)), rep(36, nrow(mat)))

layout(mat2, heights = rep(8, 4), widths = c(rep(8, 4), 3, 1, rep(8,
4), 3, 1), respect = F)   

par(mar = c(0, 0, 0, 0))

for (i in 1:16) image(matrix(rnorm(64^2), ncol = 64), col =
 tim.colors(64), axes = F)

par(oma = c(0, 0, 0, 4))
par(mar = c(0, 0, 0, 0))

image.plot( zlim = c(-3, 3) , cex = 0.7, lwd = 0.5, legend.only=TRUE,
legend.width = 15, legend.shrink = 0.75)

frame()

for (i in 1:16) image(matrix(rnorm(64^2), ncol = 64), col =
 tim.colors(64), axes = F)

par(oma = c(0, 0, 0, 4))
par(mar = c(0, 0, 0, 0))

image.plot( zlim = c(-3, 3) , cex = 0.7, lwd = 0.5, legend.only=TRUE,
legend.width = 15, legend.shrink = 0.75)




And everything goes haywire from the application of image.plot onwards. Indeed, if I replace the first image.plot call with frame(), everything goes through but of course, I do not get the first legend. So, I wonder what am I doing wrong? Also how should I fix this? Note that submitting the figures separately is not an option for me (stupid journal rules:-()

Can someone please suggest what I should do here? 

Many thanks and best wishes,
Ranjan



More information about the R-help mailing list