在grid.layout中控制内部图形边距 [英] controlling the inner figure margin within grid.layout

查看:116
本文介绍了在grid.layout中控制内部图形边距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在一个网格中绘制多个网格图. 为此,我使用以下代码:

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()

我现在想减小两个图形之间的间距,我在 gridBase 的小插图中看到,简单的图形控件(例如具有par (mar=c())的图形控件)应该可以工作,但是这里不是这样. 也许我缺少明显的东西,但我不知道为什么我无法控制边距参数. 有什么建议吗?

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提供了一些控制绘图边距的选项,

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)

这篇关于在grid.layout中控制内部图形边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆