问题描述
我是 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
code> 围绕plot
. - 重要:关闭您的设备:
dev.off()
以完成文件. - 可选:检查 pdf 文件.
- 在 LaTeX 中,在文档标题中使用
usepackage{graphicx}
,使用includegraphics[width=0.98extwidth]{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, useincludegraphics[width=0.98extwidth]{figures/myfile}
to include the figure created earlier and note that file extension is optional. - run this through
pdflatex
and enjoy.
这篇关于将 R 绘图放入 LaTeX 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!