我在这里继续我之前的帖子:
Sweave/R/LaTeX 的初学者问题(数字、参考书目)---我的第一个文档
工作代码在此处复制:
\documentclass[a4paper]{article}
\usepackage{Sweave} %%%%%%
\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}
以上运行良好RStudio
(最新)和Tinn-R
(最新)并生成所需的pdf文档。
问题:
如果我将上述文件命名为
goodex.snw
并运行 Sweave,我将获得goodex-004.pdf
带有Tinn-R
或RStudio
作为绘图的 PDF 图像的文件。为什么是尾随004
?这可以改变吗?可以
EPS
制作文件吗?Sweave 编译为 PDF 的工具是否仅通过 (PDF)LaTeX 而不是通过传统的 DVI > PS > PDF 路线?只需
with(test.frame,plot(year,value))
在R
命令窗口中运行命令即可在 y 轴上生成更多值,即 15000、20000、25000 和 30000。但是在本文顶部我的代码由 Sweave 生成的 PDF 文件中,我没有得到所有值在 y 轴上(仅 15000 和 25000)。如何在代码中直接控制绘图的大小,以便出现所有必要的 y 值?
更新:该文件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