[R] Combining grid::grid.raster plots

Axel Urbiz axel.urbiz at gmail.com
Tue Apr 11 00:55:11 CEST 2017


Dear Group,

I'd like to combine many grid::grid.raster plots into a single layout.

Here's my attempt, which does not work (i.e., does not combine the 9 images
into a single plot layout).

require(grid)

random_image <- function() {

  r <- matrix(sample(1:255, 32 * 32, replace = TRUE), nrow = 32, ncol = 32)
  g <- matrix(sample(1:255, 32 * 32, replace = TRUE), nrow = 32, ncol = 32)
  b <- matrix(sample(1:255, 32 * 32, replace = TRUE), nrow = 32, ncol = 32)
  img <- rgb(r, g, b, maxColorValue = 255)
  dim(img) <- c(32, 32)
  img

}

set.seed(1)
layout(matrix(1:9,nr=3,byr=T))
for (i in 1:9) {
 image <- random_image()
 grid.raster(image)
}

Any guidance would be highly appreciated.

Best,
Axel.

	[[alternative HTML version deleted]]



More information about the R-help mailing list