Grid display in Sweave

I have a small routine that organizes ggplot and grid graphics using the grid.arrange function in gridExtras packages. I need to infer from my routine (which nominally prints using grid.draw or returns a mesh object as an option) in my Sweave documentation. I don’t understand how to do this, because, say, I use "print", it doesn’t work like with ggplot clean graphics. I tried:

g <- ggkm(survfit.object, returns=T)
print(g)

where g is the object created by grid.arrange and has a class

> class(g)
[1] "frame" "gTree" "grob"  "gDesc"

Any help would be appreciated

Abhijit

+3
source share
1 answer

Printing an object as it is created, rather than printing a saved object, seems to work, although I could not explain why ...

\documentclass{article}
\begin{document}


<<>>=
library(ggplot2)
library(gridExtra)

d <- data.frame(x=1:10,y=1:10,z=runif(10))
g1 <- qplot(x,y,data=d)
g2 <- qplot(x,z,data=d)
@ 

<<fig=TRUE,results=hide>>=
print(grid.arrange(g1,g2,ncol=2))
@ 

\end{document}

enter image description here

+3
source

All Articles