Skip to content
Prev 78820 / 398502 Next

aligning column of xyplots and removing space between them

On 10/11/05, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:
Define

theme.novpadding <- list(layout.heights =
    list(top.padding = 0,
         main.key.padding = 0,
         key.axis.padding = 0,
         axis.xlab.padding = 0,
         xlab.key.padding = 0,
         key.sub.padding = 0,
         bottom.padding = 0))

and then add

par.settings = theme.novpadding

to all your xyplot calls.
They seem to be the same for me, but they might be different if the
y-axis labels are different. See the 'panel.width' argument in
?print.trellis.
add

scales = list(x = list(relation = "free"))
There's no better way. This behaviour is intentionally different from
base graphics.

Here's a modified version of the last part of your code:

grid.newpage()

# n and nr are number of cells and rows
n <- nr <- 3
nc <- 1  # must be 1

heights <- unit(c(2, rep(1, nr-1)), "null")
downViewport(pushLayout(nr, nc, heights = heights))

vpt <- current.vpTree(all = FALSE)

### relevant part starts here
#########################

xlab <- main <- function(x) if (x) "v"
for(k in 1:n) with(vpt$children[[k]],
       print( xyplot(v ~ v, list(v = 1:k), xlab = xlab(k == n),
       xlim = c(0,n), ylim = c(0,n), main = main(k == 1),
       par.settings = theme.novpadding,
       scales = list(x = list(draw = k == n, relation = "free", c(1, 0)),
                         y = list(alternating = 3))),
       newpage = FALSE, panel.width = list(x = 4, units = "inches"))
)

-Deepayan