Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put two 'vcd' grid graphics in a single plot?

I would like to place two (somewhat non-standard) grid graphics in a single plot in R.

Try:

require(vcd)
mosaic(Titanic)
assoc(Titanic)

The trouble is that these aren't lattice graphics, and to my knowledge do not come with a layout argument or similar. And since these are grid graphs, they're impervious to base graph tricks like par(mfrow=c(1,2)).

How can I place the two graphs above in a single plot, with both graphs on the same line?

I already tried the suggestions in How to plot grid plots on a same page?, but they don't seem to work for vcd plots. Ultimately I would like to obtain something similar to:

enter image description here

like image 238
landroni Avatar asked Sep 04 '26 00:09

landroni


1 Answers

Neither plot seems to return any object and I cant see how to grab the grobs from looking at grid.ls(). So using the idea from this answer

library(vcd) 
library(gridGraphics)
library(gridExtra)

mosaic(Titanic)  
m <- grid.grab()  

assoc(Titanic)  
a <- grid.grab()

grid.newpage()
grid.arrange(m, a, ncol=2)

enter image description here

Im sure there will be a more grid-like approach but ...

like image 79
user20650 Avatar answered Sep 05 '26 14:09

user20650



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!