我可以在命令行上尝试使用4x4绘图,但在下面的代码中不能使用for -loop和png元素.我很沮丧问题是什么,我现在已经试着理解这个时间而且无法前进.
只是$ R CMD Sweave paper.Rnw,$ pdflatex paper.tex和$ evince paper.pdf你复制后的代码下面paper.Rnw -file - ,你会得到一个1x1的情节,而不是4×4的情节.为什么?
$ mkdir Pictures
$ mkdir Data
$ cd Data
$ wget https://noppa.aalto.fi/noppa/kurssi/mat-2.3128/harjoitustyot/Mat-2_3128_data_2.xls
$ cd ..
$ cat paper.Rnw
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{graphicx}
\begin{document}
<<echo=FALSE>>=
library(gdata)
f<-read.xls('./Data/Mat-2_3128_data_2.xls')
for(i in 1:ncol(f))
{
png(paste('./Pictures/CO',i,'.png',sep =''))
par(mfrow=c(2,2))
plot(pacf(na.omit(f[,i])), main=paste('Pacf', i))
plot(acf(na.omit(f[,i])), main=paste('Acf', i))
plot(na.omit(f[,i]), main=paste('Data', i), type='l')
}
@
\subsection{Time-serie C1}
\includegraphics{./Pictures/CO1.png}
\subsection{Time-serie C2}
\includegraphics{./Pictures/CO2.png}
\subsection{Time-serie C3}
\includegraphics{./Pictures/CO3.png}
\subsection{Time-serie C4}
\includegraphics{./Pictures/CO4.png}
\subsection{Time-serie C5}
\includegraphics{./Pictures/CO5.png}
\end{document}
Run Code Online (Sandbox Code Playgroud)
函数acf和默认pacf参数.因此,不需要绘图声明(否则您将获得两个绘图和两个绘图).注意,我还添加了一个声明.plotTRUEacfpacfdev.off()
这应该工作:
for(i in 1:ncol(f))
{
png(paste('./Pictures/CO',i,'.png',sep =''))
par(mfrow=c(2,2))
pacf(na.omit(f[,i]), main=paste('Pacf', i))
acf(na.omit(f[,i]), main=paste('Acf', i))
plot(na.omit(f[,i]), main=paste('Data', i), type='l')
dev.off()
}
@
Run Code Online (Sandbox Code Playgroud)