我很了解R,但是我从Sweave开始。
[我用几种脚本在Rstudio下生成了一个报告:
在图形中R
library(ggplot2)
graph_1 <- ggplot(data=iris, aes(x = Sepal.Length, y = Sepal.Width)) + geom_point(aes(color=Species, shape=Species))
在script.Rnw
\documentclass[french,12pt]{article}
\begin{document}
... no important...
\begin{figure}[h]
\begin{center}
<< fig=TRUE, echo=FALSE, height = 2.5>>=
graph_1
@
\caption{caption figure 1}
\label{graph_1}
\end{center}
\end{figure}
\end{document}
在main.R
Sweave("script.Rnw", encoding="UTF-8")
tools:::texi2dvi(file="script.tex"), pdf=TRUE)
一切正常:我的报告(.pdf)在该文件夹中生成。但是我还有一个文件:'script-001.pdf',其中包含我的图形,并添加到同一文件夹中。
我只想要最终报告,而不想要中间文件:所以不需要'script-001.pdf'文件。有人知道这是否可能吗?
谢谢,
图形文件是必需的,以便LaTeX可以包含它。但是您可以在运行Sweave和LaTeX后安全删除它。
我也不希望我的工作目录中乱七八糟的PDF。因此,我将其保存在名为figures
的文件夹中。使用Sweave,您可以通过设置合适的前缀来完成此操作:
\SweaveOpts{prefix.string=figures/}
还有个人建议:您可能希望看看knitr –我认为它是Sweave的更强大的现代版本。