LaTeX和R捆绑?

Edw*_*its 6 latex r tex knitr

我使用R来分析统计数据并绘制直方图,散点图等.

然后我必须将所有绘图导出为PDF以手动将它们包含在LaTeX报告中.

我想知道是否有办法简化这个过程?

我很乐意写下这样的话:

\chapter{One}
\begin{r}
    qplot(...)
\end{r}
Run Code Online (Sandbox Code Playgroud)

这样的代码\begin{r},并\end{r}会产生一个情节,某个地方将它保存为PDF格式,并产生TeX这样的:

\begin{figure}[ht!]
    \includegraphics[width=1\textwidth,height=1\textheight]{/path/to/plot.pdf}
\end{figure}
Run Code Online (Sandbox Code Playgroud)

Yih*_*Xie 10

看看你的主页上的5分钟视频是否可以说服你knitr:http://yihui.name/knitr/如果你只关心LaTeX,请从2:54开始.

你的源代码是这样的:

\chapter{One}
<<plot, out.width='1\textwidth', out.height='1\textheight', fig.pos='!ht', fig.cap='your caption'>>=
    qplot(...)
@
Run Code Online (Sandbox Code Playgroud)


mne*_*nel 6

你想要的是什么knitr.

该网站有很多例子

在您的文档中,您可以执行类似的操作

<<boring-plots, fig.width=4, fig.height=4, out.width='.4\\linewidth'>>=
## two plots side by side (option fig.show='hold')
par(mar=c(4,4,.1,.1),cex.lab=.95,cex.axis=.9,mgp=c(2,.7,0),tcl=-.3,las=1)
boxplot(x)
hist(x,main='')
@
Run Code Online (Sandbox Code Playgroud)

或者甚至设置它以便你的

\begin{r}

\end{r}
Run Code Online (Sandbox Code Playgroud)

语法会起作用.

以上示例的最小示例的pdf输出

  • 谢谢!你们很快 我很高兴我能够远离SO并专注于我的编织书而不是:) (3认同)

ags*_*udy 5

Rstudio + knitr很棒

http://www.rstudio.com/ide/docs/authoring/overview
Run Code Online (Sandbox Code Playgroud)