controlling the inner figure margin within grid.layout

。_饼干妹妹 提交于 2019-12-22 08:29:50

问题


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?


回答1:


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)


来源:https://stackoverflow.com/questions/8872343/controlling-the-inner-figure-margin-within-grid-layout

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!