I'm trying to plot multiple lattice plots in a grid. To do so I'm using the following code:

plot <- xyplot(1:10~1:10)

page.layout <- grid.layout(nrow = 2, ncol = 1,
               widths = unit(c(1), "null"),
               heights = unit(c(1), "null"),
               default.units = "null",
               respect = FALSE,
               just = "centre")

pushViewport(viewport(layout = page.layout))
pushViewport(viewport(layout.pos.row = 1))
par(mar = c(5, 4, 4, 2))
print(plot, newpage = FALSE)
popViewport()
pushViewport(viewport(layout.pos.row = 2))
par(mar = c(5, 4, 4, 2))
print(plot, newpage = FALSE)
popViewport()

I'd like now to reduce the space between the two figure, I read in the vignette for gridBase, that simple graphic controls, such has par(mar=c()) should be working, but it is not the case here. Maybe I'm missing something obvious, but I can't figure out, why I can't control the margin parameters. Any suggestions?

有帮助吗?

解决方案

lattice provides some options to control the plot margins,

 p <- xyplot(1:10~1:10,
             par.settings=list(layout.heights=list(top.padding=-3, bottom.padding=-1)))

library(gridExtra)
grid.arrange(p, p, nrow=2)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top