In R, how to prevent a blank page in pdf when using gridBase to embed a subhead within a section

As explained here , it’s easy to embed the plot into an existing one thanks to gridBase , although both graphs use the basic graphics system R. However, when you save the entire figure in pdf format, the first page is always blank. How to prevent this?

Here is an example:

 require(gridBase) ## generate dummy data set.seed(1859) x <- 1:100 y <- x + rnorm(100, sd=5) ols <- lm(y ~ x) pdf("test.pdf") ## draw the first plot plot.new() # blank page also happens when using grid.newpage() pushViewport(viewport()) plot(x, y) ## draw the second plot, embedded into the first one pushViewport(viewport(x=.75,y=.35,width=.2,height=.2,just=c("center","center"))) par(plt=gridPLT(), new=TRUE) hist(ols$residuals, main="", xlab="", ylab="") popViewport(2) dev.off() 
+7
r plot
Sep 18 '12 at 16:35
source share
1 answer

I think this hacked a bit, but on my computer one file = FALSE was installed:

 pdf("test.pdf", onefile=FALSE) 

Looking for an answer (which I really didn’t find as much as I came across in the woods), I came across this post in Paul Murrell's Rhelp , which admits that the mixed grid and basic graphics confuse even Master.

+18
sept. '12 at 19:04
source share



All Articles