如何绘制并将其保存在Mac中的R中的R函数内

时间:2015-04-21 04:13:05

标签: r macos plot lattice

我的问题是,我想在整体大功能中保存一个情节来总结结果。但是,当我没有把我的绘图命令放在大函数中时,它运行得很好,但是当我运行大函数时,我的情节因为它们被损坏而无法打开。有什么选择我可以实现我的目标吗?我在下面提供的两个选项都不起作用。

谢谢你们!:)

我正在使用优胜美地系统的mac机器 这是我的代码:

library(lattice)
poissonICARMCMCPost = function(overallRes, preProcessData,path){

####Posterior part#########################################
### get the posterior information from the posterior samples
result = overallRes$result
resultSubset = overallRes$resultSubset
quartz()
acfplot(resultSubset)
dev.copy2pdf(file = paste(path, "acfplot", ".pdf", sep=""))
dev.off()
}

我也试过

poissonICARMCMCPost = function(overallRes, preProcessData,path){
####Posterior part#########################################
### get the posterior information from the posterior samples
result = overallRes$result
resultSubset = overallRes$resultSubset
pdf(paste(path, "acfplot", ".pdf", sep=""))
acfplot(resultSubset)
dev.off()
}

1 个答案:

答案 0 :(得分:1)

感谢MrFlick的精彩评论,我找到了一个现在有效的解决方案:

poissonICARMCMCPost = function(overallRes, preProcessData,path){
####Posterior part#########################################
### get the posterior information from the posterior samples   
result = overallRes$result
resultSubset = overallRes$resultSubset
quartz()
print(acfplot(resultSubset))
dev.copy2pdf(file = paste(path, "acfplot", ".pdf", sep=""))
dev.off()
}