R lattice: How to add empty plots with border to fill the gaps of defined layout

Viewed 97

I would like to create a series of figures contaning 6 or less plots within a 2x3 layout. In case if there is a figure with less than 6 plots I would like to have borders to see the structure of the layout.

For example this code gives the following figure:

n <- 3
data0 <- expand.grid(g = LETTERS[1:3], x=1:10)
data0$y <- data0$x + rnorm(nrow(data0))
xyplot(y~x|g, data=data0, layout=c(2,3), as.table=TRUE)

enter image description here

I would like to create something like this:

enter image description here

Any idea how to do this?

1 Answers

I just added 3 more groups with NA values:

data0 <- expand.grid(g = LETTERS[1:6], x=1:10)
data0$y <- data0$x + rnorm(nrow(data0))
data0[data0$g %in% LETTERS[4:6],c('x', 'y')] <- NA
xyplot(y~x|g, data=data0, layout=c(2,3), as.table=TRUE)

enter image description here

Related