让 R 绘图进入 LaTeX? [英] Getting R plots into LaTeX?

查看:36
本文介绍了让 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 需要一个明确的 print围绕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天全站免登陆