[R] R + LaTeX formula

Marc Schwartz marc_schwartz at comcast.net
Sun Dec 9 02:24:49 CET 2007

On Sun, 2007-12-09 at 01:04 +0000, Jonas Stein wrote:
> Hi,
> what is actually the best method to include R-plots into LaTeX
> documents?
> At the moment i use 
> postscript("myplot.eps", width = 12.0, height = 9.0, horizontal =
> onefile = TRUE, paper = "special",encoding = "TeXtext.enc")
> plot(foo,bar)
> dev.off()  
> But it is a bit unhandy to scale later and its difficult to get nice 
> formula in the plots.
> And how should i write formulas on the axis or at specific points? 
> Has someone had some effort in exporting plots to pstricks or pictex?
> kind regards and thank you for reading so far,

As per the Details section of ?postscript:

The postscript produced for a single R plot is EPS (Encapsulated
PostScript) compatible, and can be included into other documents, e.g.,
into LaTeX, using \includegraphics{<filename>}. For use in this way you
will probably want to set horizontal = FALSE, onefile = FALSE, paper =
"special". Note that the bounding box is for the device region: if you
find the white space around the plot region excessive, reduce the
margins of the figure region via par(mar=).

In your code above, change 'onefile = TRUE' to 'onefile = FALSE'.

For scaling you can use the LaTeX \includegraphics directive along with
several height and width arguments, such as:


You might want to review the following document:


For including formulae in R plots, see ?plotmath. You can run
example(plotmath) and there are many posts in the r-help archives on

Beyond the above, you may want to look into using SWeave, whereby you
can create entire documents, with nicely formatted tables and plots
directly from R code. More information here:


There are also a couple of articles on R News:

Friedrich Leisch. Sweave, part I: Mixing R and LATEX. R News,
2(3):28-31, December 2002.

Friedrich Leisch. Sweave, part II: Package vignettes. R News,
3(2):21-24, October 2003.


Marc Schwartz

More information about the R-help mailing list