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()
r plot
tflutre Sep 18 '12 at 16:35 2012-09-18 16:35
source share