All -- There are several other questions on this exact topic, but none of them addresses the problem I am facing. Here is a simple snippet of code. Can anyone advise what the issue here is please?
> grid.arrange(plot(rnorm(1000)),hist(rnorm(1000)), nrow=2, ncol=1)
Error in gList(list(wrapvp = list(x = 0.5, y = 0.5, width = 1, height = 1, :
only 'grobs' allowed in "gList"
The problem is that plot()
and hist()
are base graphics but not grid or ggplot graphics, hence they are not grobs ("grob" is a somewhat strange acronym for "grid graphical object"). You could either find equivalent grid plots or use a base graphics approach to stacking plots.
The way you would do the latter:
> par(mfrow = c(2, 1))
> plot(rnorm(1000))
> hist(rnorm(1000)) #are you sure you want to make a hist of 1000 *different* random numbers?
> par(mfrow = c(1, 1)) #reset this parameter
Output:
You could also consider using layout
. Type ?layout
for details.