Behavior is associated with a lazy grade of R.
Here is a minimal (?) Example:
d <- 1:3 args.list <- NULL; plot.list <- NULL; for (m in 1:3) { plot.list <- c(plot.list, list(qplot(d[m], d[m], ylab=letters[m]))) } args.list <- c(plot.list, nrow=1, ncol=3) do.call(grid.arrange, args.list)
in this case, d[m] is evaluated when do.call called. therefore, m is 3 for all panels.
here is a workaround:
d <- 1:3 args.list <- NULL; plot.list <- NULL; for (m in 1:3) { plot.list <- c(plot.list, list(qplot(d, d, data=data.frame(d=d[m]), ylab=letters[m]))) } args.list <- c(plot.list, nrow=1, ncol=3) do.call(grid.arrange, args.list)
in this case, d[m] is evaluated when qplot called, and d[m] stored in the qplot output object.
therefore, a simple solution is to pass data to qplot() or ggplot() .
source share