How to export R plots into Tex files?

r
plot

#1

Hi,

I’m a new to both R and LaTeX. I want to export R plots saved into png images into Tex format.

How to make R’s plot() function output a vector graphic and embed that into LaTeX, if at all it’s possible?

Thanks


#2

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 explicit print around plot.
important: close your device: dev.off() to finalize the file.
optional: inspect the pdf file
in LaTeX, use usepackage{graphics} 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