将 R 绘图放入 LaTeX 中? [英] Getting R plots into LaTeX?

查看:16
本文介绍了将 R 绘图放入 LaTeX 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 R 和 LaTeX 的新手,最近才发现如何使用 R 绘制标准时间序列图并将其另存为 png 图像.我担心的是,将其另存为图像然后将其嵌入 LaTeX 会使其缩放并使其看起来很丑.

I'm a newbie to both R and LaTeX and have just recently found how to plot a standard time series graph using R and save it as a png image. What I'm worried about is that saving it as an image and then embedding it into LaTeX is going to scale it and make it look ugly.

有没有办法让 R 的 plot() 函数输出矢量图形并将其嵌入到 LaTeX 中?我在这两个方面都是初学者,所以请保持温和:) 非常感谢代码片段!

Is there a way to make R's plot() function output a vector graphic and embed that into LaTeX? I'm a total beginner in both so please be gentle :) Code snippets are highly appreciated!

推荐答案

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.

这篇关于将 R 绘图放入 LaTeX 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆