将R图绘制到LaTeX中? [英] Getting R plots into LaTeX?

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

问题描述

我是R和LaTeX的新手,刚刚发现如何使用R绘制标准时间序列图并将其保存为PNG图像。我担心的是,将它保存为图像,然后将其嵌入到LaTeX中将会扩展并使其看起来很难看。



有没有办法使R的 plot()函数输出一个矢量图并将其嵌入到LaTeX中?我是一个总共初学者,所以请温柔:)代码片断,高度赞赏!

解决方案

Shane是现货,你确实想要Sweave。最终。

作为一个新手,尽管你可能最好分离任务。为此,请执行以下操作:


  1. 打开设备: pdf(figures / myfile.pdf,height =绘制您的R对象: plot(1:10,type ='l',main = 6,width = 6)
  2. 'boring') - 并且记住lattice和ggplot需要在 plot 附近显式地 print >。
  3. 重要:关闭设备: dev.off()来完成文件。

  4. 可选:在LaTeX中检查PDF文件

  5. ,在文档头中使用 usepackage {graphicx} ,使用
    >
    \includegraphics [width = 0.98\textwidth] {figures / myfile} 包含前面创建的图形,并注意文件扩展名是可选的。 li>
  6. 通过 pdflatex 运行并享受。


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:

  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\textwidth]{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天全站免登陆