R 中是否有等同于 gnuplot 的 "epslatex" 的东西?

Is there an equivalent to gnuplot's "epslatex" in R?

我正在寻找可以生成 eps 图和 tex 文件的 R 环境,就像 gnuplot.

中的 epslatex 环境

背景

以下代码显示了一个 gnuplot 文件(我想知道是否可以用 R 文件替换这个文件)。 gnuplot 的输出是两个文件:figure.texfigure.eps.

set terminal epslatex color solid
set output "/path/to/report/figure.tex"

set xlabel "2$\theta$"
set ylabel "Counts"
set xrange [20:60]
set yrange [300:14000]
# Plot col 1 against col 2, add vertical gap, e.g. (1000+())
plot 'file1.txt' using 1:2           title '<A-TITLE>' with lines, \
     'file2.txt' using 1:(1000+()) title '<B-TITLE>' with lines, \
     'file3.txt' using 1:(2000+()) title '<C-TITLE>' with lines, \
     'file4.txt' using 1:(3000+()) title '<D-TITLE>' with lines, \

请注意 gnuplot(下图)的图形输出不包含任何文本。 通过排版 LaTeX article/book/etc 添加文本。其中包含文件 figure.tex 文件(对堆栈溢出不友好)。

问题:R 可以为我做同样的事情吗?

其他语言的替代方法也很受欢迎。然而,一致的字体排版和数学符号(我有自己的 LaTeX 宏)是绝对必须的!

如上面的评论所述,您可以使用 Sweave. The simplest way to do this is to utilize the RStudio IDE 轻松生成 .tex 文件,它同时支持 Sweave 和 MFR(Markdown For R)。

Sweave 允许您在 .tex 文件中嵌入大块 R 代码; R代码是运行产生输出,然后文件被编译(不确定这是否是正确的词)从.tex到你想要的任何格式。

如果您希望输出图像是与输出 .tex 不同的文件,您可以在 Sweave 中轻松做到这一点,文件通常位于单独的目录中。为此,您需要检查块选项。

编辑添加:正如下面 Alex A. 所述,knitr 包的开发是为了解决 Sweave 的一些奇怪问题,并且紧密集成到 RStudio 中,可以解决您的一些问题也想要