[英]suppress interactive plotting in R
I would like to send a plot to a file using pdf()
, but plot.MCMCglmm()
is attempting to act interactively, which interferes with dev.off()
. 我想使用
pdf()
将图发送到文件,但是plot.MCMCglmm()
试图以交互方式进行操作,这会干扰dev.off()
。
pdf(file="model.pdf")
plot(model, random=FALSE)
Hit <Return> to see next plot: dev.off()
And the file is not closed. 并且文件未关闭。 Adding another
dev.off()
closes the file. 添加另一个
dev.off()
关闭文件。 Is there a way to suppress the interactive plotting? 有没有办法抑制交互式绘图?
EDIT example: 编辑示例:
require(MCMCglmm)
mod_dat <- data.frame( Name = rep(letters[1:3], each=10),
Group = rep(letters[1:3], 10),
Age = rep(letters[1:5], each=6),
Happy = rep(letters[1:2], 15),
x = rnorm(30),
y = rnorm(30) )
mod_out <- MCMCglmm( y~x, random=~Name+Group+Age+Happy,
data=mod_dat, verbose=FALSE )
pdf( file="model out.pdf" )
plot(mod_out)
dev.off()
dev.off()
You could modify the plot function for plot.MCMCglmm
to turn off the new page prompt. 您可以修改
plot.MCMCglmm
的绘图功能以关闭新页面提示。 You can get the code for the function by typing plot.MCMCglmm
in the console. 您可以通过在控制台中键入
plot.MCMCglmm
来获取该函数的代码。
myPlotGLMM = function (x, random = FALSE, ...)
{
nF <- x$Fixed$nfl
#devAskNewPage.orig <- devAskNewPage()
if (random) {
nF <- sum(rep(x$Random$nrl, x$Random$nfl)) + nF
if (nF != dim(x$Sol)[2]) {
stop("random effects not saved and cannot be plotted")
}
}
plot(x$Sol[, 1:nF, drop = FALSE], ...)
#devAskNewPage(TRUE)
if (is.null(x$Lambda) == FALSE) {
plot(x$Lambda, ...)
#devAskNewPage(TRUE)
}
plot(x$VCV, ...)
#devAskNewPage(devAskNewPage.orig)
}
myPlotGLMM(model)
Another option is to plot everything onto one page. 另一种选择是将所有内容绘制到一页上。 Without a reproducible example I can't test this but this should work:
没有可复制的示例,我无法测试,但这应该可以工作:
pdf(file="model.pdf")
par(mfrow=c(2,2))
plot(model, random=FALSE)
dev.off()
So if this generated four plots, they would be arranged on one page in 2 x2 grid. 因此,如果生成了四张图,它们将以2 x2网格排列在一页上。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.