Skip to content

R and LaTeX

5 messages · David Kaplan, Ko-Kang Kevin Wang, Andrew Robinson +2 more

#
Hi all,

I have started using LaTeX for writing papers and I have heard that R 
works well with LaTeX.  I'm specifically interested in how I can have 
LaTeX read in R generated graphics - for example graphs formed by 
matplot, or other such  processes.  Does anyone out there use LaTeX and 
can point me in the right direction?

Thanks

David
#
Hi David,

You can export the graphs in (encapsulated) postscript format, or in 
PDF/PNG/JPEG format.  The following functions may be helpful:
   postscript()
   png()
   pdf()

You may also want to check out Sweave 
(http://www.ci.tuwien.ac.at/~leisch/Sweave/), it allows you to integrate 
LaTeX and R neatly.

Cheers,

Kevin
David Kaplan wrote:

  
    
#
Hi David,

I strongly recommend that you use Sweave to mediate LaTeX and R.

http://www.ci.tuwien.ac.at/~leisch/Sweave/FAQ.html

Cheers

Andrew
On Sat, Dec 09, 2006 at 10:39:19PM -0600, David Kaplan wrote:

  
    
#
Or if you mean how to annotate plots with mathematical symbols and 
formulas, see ?plotmath.

Uwe Ligges
Andrew Robinson wrote:
1 day later
#
David Kaplan <dkaplan at education.wisc.edu> wrote:

            
David--

The basic paradigm is to save the graph from R in encapsulated
Postscript format.  The procedure can vary slightly by the OS
you are using R under.  Under Windows, I usually generate the
graphics in the windows() device, then use savePlot to save it
to eps.

In Latex, you can put 

\usepackage{graphicx}

in the document preamble and something like

\begin{figure}[!th]
\includegraphics[height=8in]{figurename.eps}\\
\end{figure}

into the text to put the figure in a float.  To put in exactly
where the statement occurs, omit putting it into a figure
environment.

HTH,

--Mike