将R图绘制到LaTeX中? [英] Getting R plots into LaTeX?
问题描述
我是R和LaTeX的新手,刚刚发现如何使用R绘制标准时间序列图并将其保存为PNG图像。我担心的是,将它保存为图像,然后将其嵌入到LaTeX中将会扩展并使其看起来很难看。
有没有办法使R的 plot()
函数输出一个矢量图并将其嵌入到LaTeX中?我是一个总共初学者,所以请温柔:)代码片断,高度赞赏!
Shane是现货,你确实想要Sweave。最终。
作为一个新手,尽管你可能最好分离任务。为此,请执行以下操作:
- 打开设备:
pdf(figures / myfile.pdf,height =绘制您的R对象:
plot(1:10,type ='l',main = 6,width = 6)
。 'boring') - 并且记住lattice和ggplot需要在 - 重要:关闭设备:
dev.off()
来完成文件。 - 可选:在LaTeX中检查PDF文件
- ,在文档头中使用
usepackage {graphicx}
,使用
>
\includegraphics [width = 0.98\textwidth] {figures / myfile}
包含前面创建的图形,并注意文件扩展名是可选的。 li>
- 通过
pdflatex
运行并享受。
plot 附近显式地 print >。
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.
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 is spot-on, you do want Sweave. Eventually.
As a newbie, you may better off separating task though. For that, do this:
- 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\textwidth]{figures/myfile}
to include the figure created earlier and note that file extension is optional. - run this through
pdflatex
and enjoy.
这篇关于将R图绘制到LaTeX中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!