让 R 绘图进入 LaTeX? [英] Getting R plots into 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:
- 打开一个设备:
pdf("figures/myfile.pdf", height=6, width=6)
. - 绘制你的 R 对象:
plot(1:10, type='l', main='boring')
-- 记住 lattice 和 ggplot 需要一个明确的print代码>围绕
plot
. - 重要提示:关闭您的设备:
dev.off()
以完成文件. - 可选:检查 pdf 文件.
- 在 LaTeX 中,在文档标题中使用
usepackage{graphicx}
,使用includegraphics[width=0.98 extwidth]{figures/myfile}
包含之前创建的图,并注意文件扩展名是可选的. - 通过
pdflatex
运行它并享受.
- open a device:
pdf("figures/myfile.pdf", height=6, width=6)
. - plot your R object:
plot(1:10, type='l', main='boring')
-- and remember that lattice and ggplot need an explicitprint
aroundplot
. - important: close your device:
dev.off()
to finalize the file. - optional: inspect the pdf file.
- 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. - run this through
pdflatex
and enjoy.
这篇关于让 R 绘图进入 LaTeX?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!