这可能很愚蠢,但是如何动态创建类似vpTree
的
library(grid)
grid.newpage()
vpTree( viewport(layout=grid.layout(2,2), name = "body"), vpList(viewport(name= "a"), viewport(name ="b"), viewport(name = "c"), viewport(name = "d")))
#> viewport[body]->(viewport[a], viewport[b], viewport[c], viewport[d])
我无法传递视口列表:
library(grid)
grid.newpage()
n <- c(viewport(name= "a"), viewport(name ="b"), viewport(name = "c"), viewport(name = "d"))
vpTree( viewport(layout=grid.layout(2,2), name = "body"), vpList(n))
#> Error in vpListFromList(vps): only viewports allowed in 'vpList'
有什么想法吗?
答案 0 :(得分:0)
创建vpList的方法不正确。 试试这个
##Supply same list to variable and then pass it in function
library(grid)
grid.newpage()
n <- vpList(viewport(name= "a"), viewport(name ="b"), viewport(name = "c"), viewport(name = "d"))
vpTree( viewport(layout=grid.layout(2,2), name = "body"), n)
答案 1 :(得分:0)
vpList
要做的第一件事是将其参数转换为列表。我需要使用自定义函数覆盖网格中的vpList
函数以绕过
> vpList
function (...)
{
vps <- list(...)
vpListFromList(vps)
}
<bytecode: 0x000002e14a815a60>
<environment: namespace:grid>
到
vpList <- function (vps)
{
grid:::vpListFromList(vps)
}
赞:
library(grid)
grid.newpage()
vpListX <- function (vps)
{
grid:::vpListFromList(vps)
}
n <- list(viewport(name= "a"), viewport(name ="b"), viewport(name = "c"), viewport(name = "d"))
vpTree( viewport(layout=grid.layout(2,2), name = "body"), vpListX(n))