【发布时间】:2011-12-01 08:21:24
【问题描述】:
我在这里继续我之前的帖子:
Beginner's questions (figures, bibliography) with Sweave/R/LaTeX---my first document
工作代码在这里复制:
\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,我将获得带有Tinn-R或RStudio的文件goodex-004.pdf作为绘图的 PDF 图像。为什么尾随004?这个可以改吗?可以生成
EPS文件吗? Sweave编译成PDF的工具是不是只能通过(PDF)LaTeX而不是通过传统的DVI>PS>PDF路线?只需在
R命令窗口中运行命令with(test.frame,plot(year,value))即可在 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
【问题讨论】:
-
您的绘图生成未连接到 Sweave 或 LaTeX。你需要在 R 中解决这个问题(在另一个问题中做一个小的、独立的例子)。关于 Sweave,你见过吗? stat.epfl.ch/webdav/site/stat/shared/Regression/…
-
@Roman 感谢这个有用的链接。
-
@Roman 在我的理解中,情节生成与Sweave有关。我确实用 R 代码(15000、20000、25000 300000)解释了我在 y 轴上得到了什么,而使用 Sweave 我只得到 15000 和 25000。我不明白这里很难理解什么。 1 票赞成
-
如何在此处包含图片?