Getting R plots into LaTeX?
graphics, latex, r, vector-graphics
Solution
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 explicit `print` around `plot`.
- 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.
Problem
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!