sweave/r/latexを備えた初心者の質問(図、参考文献)---私の最初のドキュメント

StackOverflow https://stackoverflow.com/questions/8337536

  •  26-10-2019
  •  | 
  •  

質問

始めたばかりです SweaveR. 。ここで私が使用しています R いくつかのデータを出力すると、プロットも含めようとしています。コードは揺れません。私は1つを持っている Sweave よくコンパイルするWebからの例 RStudioLaTeX.

\documentclass[a4paper]{article}
\begin{document}
<<echo=TRUE>>=
x <- rnorm(100)
xm <- mean(x)
xm
@

<<echo=FALSE>>=
x <- rnorm(100)
xm <- mean(x)
xm
@

<<echo=TRUE>>= 
test.frame<-read.table(file="apples.d",header=T,sep= "")
names(test.frame)
head(test.frame)
class(test.frame)
@
\begin{figure}[htbp]
\begin{center}
\setkeys{Gin}{width=0.5\textwidth}
<<echo=FALSE,fig=TRUE,width=4,height=4>>=
plot(year,value)
@
\end{center}
\end{document}

およびファイルapples.dが含まれます:

#Number of apples I ate
year value
8   12050  #year 2008  
9   15292  #year 2009 
10  23907  #year 2010 
11  33997  #year 2011

私は何が間違っているのですか?

その他の関連する質問:

ありません Sweave ドキュメントサポートは正常です LaTeX bibliography ファイル。コンピレーションを行う方法は?

どうもありがとう...

役に立ちましたか?

解決

%%%%または####でマークされたいくつかの問題が修正されました

\documentclass[a4paper]{article}
\begin{document}
<<echo=TRUE>>=
x <- rnorm(100)
xm <- mean(x)
xm
@

<<echo=FALSE>>=
x <- rnorm(100)
xm <- mean(x)
xm
@

<<echo=TRUE>>= 
##### Remove all comments from your data file 
test.frame<-read.table(file="apples.d",header=T,sep= "")
names(test.frame)
head(test.frame)
class(test.frame)
@

\begin{figure}[htbp]
\begin{center}
\setkeys{Gin}{width=0.5\textwidth}
<<echo=FALSE,fig=TRUE,width=4,height=4>>=
#### Must tell plot where to get the data from. Could also use test.frame$year
with(test.frame,plot(year,value))
@
\end{center}
\end{figure}
\end{document}

他のヒント

Sweaveは参考文献の世話をしないので、自分でそれをコンパイルする必要があります。一部の人々はRスクリプトでこのジョブを自動化したと思いますが、経験豊富なラテックスユーザーの場合はLyxを使用することをお勧めします。 LyxはSweaveを公式にサポートしており、LaTexで必要なものをインテリジェントに(参考文献を含む)世話をします。マニュアルを参照してください: https://github.com/downloads/yihui/lyx/sweave.pdf

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top