hereで説明されているように、両方のプロットが R の基本グラフィックス システムを使用していても、既存のプロットに簡単に埋め込むことができgridBase
ます。ただし、図全体を pdf に保存すると、最初のページは常に空白になります。これを防ぐ方法は?
以下に例を示します。
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()