grid.layout
用于在一个视图上创建多个图层。大部分参数都很好理解,例如nrow和ncol就是声明行和列各有多少个图层。widths和heigths则是声明行高和列宽。比较难以理解的是参数,respect的参数说明是
If a logical, this indicates whether row heights and column widths should respect each other.
根据我在牛津高阶英汉双解词典查repsect的含义,作为动词,它的含义是尊重;尊敬;仰慕;慎重对待;所以直译就是,行高和列宽相互尊重。我读完之后还是不理解,因此我就找了一个例子帮助我理解。
我将一个视图分成了3x3共9个图层,在每个图层上,都画一个圆圈,代码和图形如下
grid.newpage()
vplay <- grid.layout(nrow=3,ncol = 3)
pushViewport(viewport(layout = vplay))
for (i in 1:3){
for (j in 1:3){
pushViewport(viewport(layout.pos.col = i, layout.pos.row = j))
grid.circle()
upViewport()
}
}
grid.newpage()
vplay <- grid.layout(nrow=3,ncol = 3, respect = T)
pushViewport(viewport(layout = vplay))
for (i in 1:3){
for (j in 1:3){
pushViewport(viewport(layout.pos.col = i, layout.pos.row = j))
grid.circle()
upViewport()
}
}
结论:respect 保证图层是方形。