Bingzhang Chen
2015-Feb-16 00:36 UTC
[R] Pass additional arguments to do.call(grid.arrange, plots)
Hi R users,
I have a problem on how to pass an extra argument to do. call:
The example codes are:
#--------------------------------------------
require(ggplot2)
plots = lapply(1:5, function(.x) qplot(1:10,rnorm(10),
main=paste("plot",.x)))
require(gridExtra)
do.call(grid.arrange, plots)
#---------------------------------------------
I want to force the composite figures into 2 rows by adding 'now = 2'
in the function 'grid.arrange'. How can I do it?
I searched on google but could not find a workable solution.
I am working on RStudio 0.98.1102 on OSX Yosemite 10.10.2.
Thanks a lot,
Bingzhang
--
Bingzhang Chen
Ph. D.,
State Key Lab of Marine Environmental Science,
College of Oceanography and Environmental Science,
Xiamen University,
Xiamen, Fujian 361005
P. R. China
David Winsemius
2015-Feb-16 07:37 UTC
[R] Pass additional arguments to do.call(grid.arrange, plots)
On Feb 15, 2015, at 4:36 PM, Bingzhang Chen wrote:> Hi R users, > > I have a problem on how to pass an extra argument to do. call: > > The example codes are: > > #-------------------------------------------- > require(ggplot2) > plots = lapply(1:5, function(.x) qplot(1:10,rnorm(10), main=paste("plot",.x))) > require(gridExtra) > do.call(grid.arrange, plots) > #--------------------------------------------- > > I want to force the composite figures into 2 rows by adding 'now = 2' > in the function 'grid.arrange'. How can I do it? > I searched on google but could not find a workable solution.Wouldn't it just be: do.call(grid.arrange, c(plots, nrow=2) ) -- David.> > I am working on RStudio 0.98.1102 on OSX Yosemite 10.10.2. > Thanks a lot, > Bingzhang > > -- > Bingzhang Chen > Ph. D., > State Key Lab of Marine Environmental Science, > College of Oceanography and Environmental Science, > Xiamen University, > Xiamen, Fujian 361005 > P. R. China > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.David Winsemius Alameda, CA, USA
Rolf Turner
2015-Feb-16 08:07 UTC
[R] Pass additional arguments to do.call(grid.arrange, plots)
On 16/02/15 13:36, Bingzhang Chen wrote:> Hi R users, > > I have a problem on how to pass an extra argument to do. call: > > The example codes are: > > #-------------------------------------------- > require(ggplot2) > plots = lapply(1:5, function(.x) qplot(1:10,rnorm(10), main=paste("plot",.x))) > require(gridExtra) > do.call(grid.arrange, plots) > #--------------------------------------------- > > I want to force the composite figures into 2 rows by adding 'now = 2'You mean 'nrow = 2', but I wasn't fooled for an instant! :-)> in the function 'grid.arrange'. How can I do it? > I searched on google but could not find a workable solution. > > I am working on RStudio 0.98.1102 on OSX Yosemite 10.10.2.Try: do.call(grid.arrange,c(plots,list(nrow=2)) The second argument to do.call() consists of a list constituting the arguments to the first argument. So just append the argument you want to use, to this list. Easy, once you know. :-) cheers, Rolf Turner P. S. Thank you for providing a clear and reproducible example. R. T. -- Rolf Turner Technical Editor ANZJS Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276 Home phone: +64-9-480-4619