【问题标题】:LaTeX and R bundle?LaTeX 和 R 捆绑?
【发布时间】:2012-12-07 05:05:29
【问题描述】:

我正在使用 R 来分析统计数据并绘制直方图、散点图等。

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

不知道有没有办法简化这个过程?

我很乐意写如下内容:

\chapter{One}
\begin{r}
    qplot(...)
\end{r}

这样\begin{r}\end{r} 之间的代码将生成一个绘图,将其保存为PDF 并生成TeX,如下所示:

\begin{figure}[ht!]
    \includegraphics[width=1\textwidth,height=1\textheight]{/path/to/plot.pdf}
\end{figure}

【问题讨论】:

    标签: r latex tex knitr


    【解决方案1】:

    看看knitr主页上的5分钟video能不能说服你: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(...)
    @
    

    【讨论】:

    • 谢谢!它看起来很整洁。
    【解决方案2】:

    你想要的是knitr

    网站有lots of examples

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

    <<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='')
    @
    

    或者甚至设置为您的

    \begin{r}
    
    \end{r}
    

    语法可以工作。

    上面示例来自minimal examplepdf output

    【讨论】:

    • 谢谢!我以前怎么可能不知道!
    • 谢谢!你们真快。我很高兴我能够远离 SO,而是专注于我的 knitr 书 :)
    【解决方案3】:

    Rstudio +knitr 很棒

    http://www.rstudio.com/ide/docs/authoring/overview
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-24
      • 2012-08-30
      • 2019-06-13
      • 1970-01-01
      • 2012-03-28
      • 2019-04-14
      • 2017-12-13
      • 2014-11-26
      相关资源
      最近更新 更多