问题
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