On 07/13/2011 10:59 AM, Brian Danielak wrote:
> My situation is that I'm working on a function
> <https://github.com/briandk/granova/blob/dev/R/granova.contr.ggplot.R>
> that outputs an arbitrary number of plots (depending upon the input data
> supplied by the user). The function returns a list of n plots, and I'd
> like to lay those plots out in 2 x 2 formation. I'm struggling with the
> simultaneous problems of:
>
> 1. How can I allow the flexibility to be handed an arbitrary (n)
> number of plots?
> 2. How can I also specify I want them laid out 2 x 2
>
> My current strategy uses grid.arrange from the gridExtra package. It's
> probably not optimal, especially since, and this is key, it /totally
> doesn't work/. Here's my commented sample code, experimenting with three
Have you tried
args.list <- c(plot.list, list(nrow=2, ncol=2)) ...
?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAk4dtAIACgkQc5UpGjwzenNhCwCfSGH8B7uQSJZcUS5snjqjElbt
rKkAn1RpvFBGdZoGbtkrDBmb52MCGnhr
=SJzf
-----END PGP SIGNATURE-----
Brian Danielak <brian.d...@gmail.com>
Sent by: ggp...@googlegroups.com 07/13/2011 10:59 AM
|
|
--
You received this message because you are subscribed to the ggplot2 mailing
list.
Please provide a reproducible example: http://gist.github.com/270442
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2
This communication may contain privileged and/or confidential information. It is intended solely for the use of the addressee. If you are not the intended recipient, you are strictly prohibited from disclosing, copying, distributing or using any of this information. If you received this communication in error, please contact the sender immediately and destroy the material in its entirety, whether electronic or hard copy. This communication may contain nonpublic personal information about consumers subject to the restrictions of the Gramm-Leach-Bliley Act. You may not directly or indirectly reuse or redisclose such information for any purpose other than to provide the services for which you are receiving the information. 127 Public Square, Cleveland, OH 44114
Have you tried
args.list <- c(plot.list, list(nrow=2, ncol=2)) ...
Try this,
require(ggplot2)
require(gridExtra)
plots = llply(1:11, function(.x) qplot(1:10,rnorm(10),
main=paste("plot",.x)))
params <- list(nrow=2, ncol=2)
n <- do.call(prod, params)
pages <- length(plots) %/% n + as.logical(length(plots) %% n)
groups <- split(seq_along(plots), gl(pages, n, length(plots)))
print(groups)
for (g in groups){
dev.new()
do.call(grid.arrange, c(plots[g], params))
}
[cross-posted from SO for completeness]
HTH,
baptiste