且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将 R 绘图放入 LaTeX 中?

更新时间:1970-01-01 07:59:06

Shane 恰到好处,您确实需要 Sweave.最终.

Shane is spot-on, you do want Sweave. Eventually.

作为新手,您***将任务分开.为此,请执行以下操作:

As a newbie, you may better off separating task though. For that, do this:

  1. 打开一个设备:pdf("figures/myfile.pdf", height=6, width=6).
  2. 绘制您的 R 对象:plot(1:10, type='l', main='boring') -- 请记住,lattice 和 ggplot 需要显式 printcode> 围绕 plot.
  3. 重要:关闭您的设备:dev.off() 以完成文件.
  4. 可选:检查 pdf 文件.
  5. 在 LaTeX 中,在文档标题中使用 usepackage{graphicx},使用
    includegraphics[width=0.98 extwidth]{figures/myfile} 包含之前创建的图形并注意文件扩展名是可选的.
  6. 通过 pdflatex 运行它并享受.
  1. open a device: pdf("figures/myfile.pdf", height=6, width=6).
  2. plot your R object: plot(1:10, type='l', main='boring') -- and remember that lattice and ggplot need an explicit print around plot.
  3. important: close your device: dev.off() to finalize the file.
  4. optional: inspect the pdf file.
  5. in LaTeX, use usepackage{graphicx} in the document header, use
    includegraphics[width=0.98 extwidth]{figures/myfile} to include the figure created earlier and note that file extension is optional.
  6. run this through pdflatex and enjoy.