Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Only grobs allowed in gList

Tags:

plot

r

gridextra

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"
like image 638
skafetaur Avatar asked Mar 12 '17 01:03

skafetaur


1 Answers

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:

enter image description here

You could also consider using layout. Type ?layout for details.

like image 154
John Coleman Avatar answered Sep 17 '22 07:09

John Coleman