r - Arranging GGally plots with gridExtra? -


i'd arrange ggpairs plots arrangegrob:

library(ggally) library(gridextra)  df <- structure(list(var1 = 1:5, var2 = 4:8, var3 = 6:10), .names = c("var1", "var2", "var3"), row.names = c(na, -5l), class = "data.frame")  p1 <- ggpairs(df, 1:3)  p2 <- ggpairs(df, 1:2)  p <- arrangegrob(p1, p2, ncol=2) 

which results in error:

error in arrangegrob(p1, p2, ncol = 2) : input must grobs! 

is there way work around problem?

unfortunately, cannot see how possible.

first, it's not going work gridextra, since arrangegrob operates on tablegrob objects:

> ggplotgrob(qplot(1:100)) stat_bin: binwidth defaulted range/30. use 'binwidth = x' adjust this. tablegrob (6 x 5) "layout": 8 grobs   z     cells       name                                 grob 1 0 (1-6,1-5) background      rect[plot.background.rect.3349] 2 3 (3-3,3-3)     axis-l absolutegrob[grid.absolutegrob.3341] 3 1 (4-4,3-3)     spacer                       zerogrob[null] 4 2 (3-3,4-4)      panel               gtree[grid.gtree.3329] 5 4 (4-4,4-4)     axis-b absolutegrob[grid.absolutegrob.3335] 6 5 (5-5,4-4)       xlab         text[axis.title.x.text.3343] 7 6 (3-3,2-2)       ylab         text[axis.title.y.text.3345] 8 7 (2-2,4-4)      title           text[plot.title.text.3347] 

the inner representation of ggpairs object contains methods called, not actual grobs:

> str(p1$plots) list of 9  $ : chr "ggally_diagaxis(ggally_data, ggplot2::aes(x = var1))"  $ : chr "ggally_cor(ggally_data, ggplot2::aes(x = var2, y = var1))"  $ : chr "ggally_cor(ggally_data, ggplot2::aes(x = var3, y = var1))"  $ : chr "ggally_points(ggally_data, ggplot2::aes(x = var1, y = var2))"  $ : chr "ggally_diagaxis(ggally_data, ggplot2::aes(x = var2))"  $ : chr "ggally_cor(ggally_data, ggplot2::aes(x = var3, y = var2))"  $ : chr "ggally_points(ggally_data, ggplot2::aes(x = var1, y = var3))"  $ : chr "ggally_points(ggally_data, ggplot2::aes(x = var2, y = var3))"  $ : chr "ggally_diagaxis(ggally_data, ggplot2::aes(x = var3))" 

the whole work of constructing actual grobs done ggally:::print.ggpairs. take @ source code , see grid.newpage() along multiple popviewports , pushviewports. means low-level grid approach (e.g. described here) not applicable, since grid constructions overwritten ggally:::print.ggpairs.

there's way, of course. modifying source code option, though believe it's long , difficult path task. i'd happy proven wrong if can come simple workaround.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -