我想用网格指定的布局在四个区域内创建 R 图。此外,gridBase 应该用于在使用基本图形的区域中实际绘制。下面是一个例子。问题是这 4 个地块没有绘制在四个不同的区域中,它们相当重叠。
require(grid)
require(gridBase)
## set up the grid layout
gl <- grid.layout(2, 2, widths=unit(c(3, 3), "inches"),
heights=unit(c(3, 3), "inches"))
pushViewport(viewport(layout=gl)) # use this layout in a viewport
## plot
par. <- par(no.readonly=TRUE) # save plot settings
vps <- baseViewports() # create list of grid viewports corresponding to inner, figure, and plot regions
pushViewport(vps$inner, vps$figure, vps$plot)
for(i in 1:2) { # rows
for(j in 1:2) { # columns
pushViewport(viewport(layout.pos.row=i, layout.pos.col=j))
par(plt=gridPLT(), new=TRUE)
x <- 1:10
plot(x, x+runif(10), type="b")
upViewport()
}
}
par(par.) # reset plot settings