Dear list, I'm trying to arrange various grid objects on a page using a frameGrob. It works fine with basic grobs (textGrob, gTree, etc.), and also with ggplot2 objects using the ggplotGrob() function. I am however stuck with lattice. As far as I understand, lattice produces a list of class trellis, which is eventually displayed using the plot.trellis method. I am not sure if/how one can convert this list into a high-level grob. I tried the following, latticeGrob <- function(p, ...){ grob(p=p, ..., cl="lattice") } drawDetails.lattice <- function(x, recording=FALSE){ lattice:::plot.trellis(x$p) } p1 <- xyplot(1:10 ~ 1:10) g1 <- latticeGrob(p1) grid.draw(g1) # works fine but, fg <- frameGrob(layout = grid.layout(1,1)) fg <- placeGrob(fg, g1, row = 1, col = 1) grid.draw(fg) Error in UseMethod("depth") : no applicable method for 'depth' applied to an object of class "NULL" Ideas are most welcome, Best regards, baptiste> sessionInfo()R version 2.10.1 RC (2009-12-06 r50690) i386-apple-darwin9.8.0 locale: [1] en_GB.UTF-8/en_GB.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8 attached base packages: [1] grid tools stats graphics grDevices utils datasets methods base other attached packages: [1] ggplot2_0.8.7 digest_0.4.1 reshape_0.8.3 plyr_0.1.9 proto_0.3-8 gridExtra_0.5 lattice_0.17-26 gtools_2.6.1
What's wrong with using grid.grabExpr? p1 <- xyplot(1:10 ~ 1:10) g1 <- grid.grabExpr(print(p1)) I can imagine there would be potential problems to do with the plot-time aspect and layout calculations... On 19 March 2010 21:51, baptiste auguie <baptiste.auguie at googlemail.com> wrote:> Dear list, > > I'm trying to arrange various grid objects on a page using a > frameGrob. It works fine with basic grobs (textGrob, gTree, etc.), and > also with ggplot2 objects using the ggplotGrob() function. I am > however stuck with lattice. As far as I understand, lattice produces a > list of class trellis, which is eventually displayed using the > plot.trellis method. I am not sure if/how one can convert this list > into a high-level grob. I tried the following, > > latticeGrob <- function(p, ...){ > ?grob(p=p, ..., cl="lattice") > } > > drawDetails.lattice <- function(x, recording=FALSE){ > ?lattice:::plot.trellis(x$p) > } > > p1 <- xyplot(1:10 ~ 1:10) > g1 <- latticeGrob(p1) > > grid.draw(g1) # works fine > > but, > > fg <- frameGrob(layout = grid.layout(1,1)) > fg <- placeGrob(fg, g1, row = 1, col = 1) > grid.draw(fg) > > Error in UseMethod("depth") : > ?no applicable method for 'depth' applied to an object of class "NULL" > > Ideas are most welcome, > > Best regards, > > baptiste > >> sessionInfo() > R version 2.10.1 RC (2009-12-06 r50690) > i386-apple-darwin9.8.0 > > locale: > [1] en_GB.UTF-8/en_GB.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8 > > attached base packages: > [1] grid ? ? ?tools ? ? stats ? ? graphics ?grDevices utils > datasets ?methods ? base > > other attached packages: > [1] ggplot2_0.8.7 ? digest_0.4.1 ? ?reshape_0.8.3 ? plyr_0.1.9 > proto_0.3-8 ? ? gridExtra_0.5 ? lattice_0.17-26 gtools_2.6.1 > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Felix Andrews / ??? Postdoctoral Fellow Integrated Catchment Assessment and Management (iCAM) Centre Fenner School of Environment and Society [Bldg 48a] The Australian National University Canberra ACT 0200 Australia M: +61 410 400 963 T: + 61 2 6125 4670 E: felix.andrews at anu.edu.au CRICOS Provider No. 00120C -- http://www.neurofractal.org/felix/
Hi baptiste auguie wrote:> Dear list, > > I'm trying to arrange various grid objects on a page using a > frameGrob. It works fine with basic grobs (textGrob, gTree, etc.), and > also with ggplot2 objects using the ggplotGrob() function. I am > however stuck with lattice. As far as I understand, lattice produces a > list of class trellis, which is eventually displayed using the > plot.trellis method. I am not sure if/how one can convert this list > into a high-level grob. I tried the following, > > latticeGrob <- function(p, ...){ > grob(p=p, ..., cl="lattice") > } > > drawDetails.lattice <- function(x, recording=FALSE){ > lattice:::plot.trellis(x$p)Try ... lattice:::plot.trellis(x$p, newpage=FALSE) Paul> } > > p1 <- xyplot(1:10 ~ 1:10) > g1 <- latticeGrob(p1) > > grid.draw(g1) # works fine > > but, > > fg <- frameGrob(layout = grid.layout(1,1)) > fg <- placeGrob(fg, g1, row = 1, col = 1) > grid.draw(fg) > > Error in UseMethod("depth") : > no applicable method for 'depth' applied to an object of class "NULL" > > Ideas are most welcome, > > Best regards, > > baptiste > >> sessionInfo() > R version 2.10.1 RC (2009-12-06 r50690) > i386-apple-darwin9.8.0 > > locale: > [1] en_GB.UTF-8/en_GB.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8 > > attached base packages: > [1] grid tools stats graphics grDevices utils > datasets methods base > > other attached packages: > [1] ggplot2_0.8.7 digest_0.4.1 reshape_0.8.3 plyr_0.1.9 > proto_0.3-8 gridExtra_0.5 lattice_0.17-26 gtools_2.6.1 > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 paul at stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~paul/