Passing a vector to grid.arrange as a list of arguments.

自古美人都是妖i 提交于 2019-12-13 06:27:26

问题


So I'm trying to use a vector to recapitulate this command, which works well on my data

grid.arrange(Sig1.plot,Sig2.plot,Sig3.plot,Sig4.plot).

The vector is

> Plots.restricted
[1] "Sig1.plot,Sig2.plot,Sig3.plot,Sig4.plot"

> class(Plots.restricted)
[1] "character"

However, doing

grid.arrange(as.name(Plots.restricted),ncol=1) 

returns the following error

Error in arrangeGrob(..., as.table = as.table, clip = clip, main = main,  : 
input must be grobs!

Alternatively, I tried

Plots.reference<-   paste(c(rep("Sig",ncol(Signatures)-1)),c(2:ncol(Signatures)-1),c(rep(".plot",ncol(Signatures)-1)),sep="",collapse=",")

where Plots.reference now produces a character vector of length 1.

grid.arrange(as.name(Plots.reference)) and grid.arrange(as.symbol(Plots.reference))

though continue to return the error.

What am I doing wrong?


回答1:


You can try this:

 do.call(grid.arrange, lapply(Plots.restricted, as.name))

or alternatively:

 do.call(grid.arrange, lapply(Plots.restricted, get))


来源:https://stackoverflow.com/questions/21611441/passing-a-vector-to-grid-arrange-as-a-list-of-arguments

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