Problem 1: No reproducible example.
Problem 2: You allude to the function multiplot(). Assuming it comes
from an R package and is not one of your own invention, there are at
least six CRAN packages with a function named multiplot(): coefplot,
blowtorch, phonTools, abf2, optiRum and Rmisc, which i got from
library(sos)
findFn("multiplot")
You have not mentioned where your multiplot() function comes from.
David Guy has pointed out a simple solution to your problem:
library(gridExtra)
do.call(grid.arrange, obj)
Note that ggplots are produced from grid graphics, so if you're using
a multiplot() function from somewhere, you should make sure that it
supports grid graphics objects. The gridExtra package does; I have no
idea about the others.
To answer your last question, it is highly unlikely that unequal
numbers of bars are the problem since the plots are saved in separate
objects. Below is a reproducible example.
# Create four data frames - note the unequal number of categories
ds1 <- data.frame(x = sample(LETTERS[1:5], 100, replace = TRUE))
ds2 <- data.frame(x = sample(LETTERS[1:4], 100, replace = TRUE))
ds3 <- data.frame(x = sample(LETTERS[1:6], 100, replace = TRUE))
ds4 <- data.frame(x = sample(LETTERS[1:5], 100, replace = TRUE))
# Create a simple function to plot a single data frame
plotfun <- function(d)
{
require(ggplot2)
ggplot(d, aes(x = x)) + geom_bar(fill = "darkorange")
}
# Create a list of ggplot objects
L <- lapply(paste0("ds", 1:4), function(z) plotfun(get(z)))
# Use do.call() to invoke grid.arrange() on the list of plots
library(gridExtra)
do.call(grid.arrange, L)
## Another way that avoids do.call() and allows
# grid.arrange() arguments to be specified - plot
# objects are in the global environment rather than a list object
p1 <- ggplot(ds1, aes(x = x)) + geom_bar(fill = "darkorange")
p2 <- p1 %+% ds2 # Same plot structure as p1, using data ds2
p3 <- p1 %+% ds3
p4 <- p1 %+% ds4
grid.arrange(p1, p2, p3, p4, ncol = 2)
Dennis