R graphs in LaTeX documents?
[Sorry, I forgot the dev.copy2eps alternative and to make the answer
complete so this answer could be refered to when others ask the same
question again I also added the 'paper="special' argument (as dev.copy2eps
do)]
You have to save your plots/figures in EPS format. EPS is basically the
same as PS (postscript), but it is a one-page document with a
"BoundingBox".
Example
In [R]:
Alternative 1: Generate the plot *first* and then the eps file
...
plot(sin(1:10), pch="+")
dev.copy2eps("myFigure.eps")
...
Alternative 2: Generate the plot *first* and then the eps file
(basically the same result as the above)
...
plot(sin(1:10), pch="+")
dev.print(device=postscript, "myFigure.eps",
onefile=FALSE, horizontal=FALSE, paper="special")
...
Alternative 3: Generate the eps file directly *without* opening
a plotting window first.
...
postscript(file="myFigure.eps",
onefile=FALSE, horizontal=FALSE, paper="special")
plot(sin(1:10), pch="+")
dev.off()
...
Note that the arguments 'onefile=FALSE, horizontal=FALSE' (and
'paper="special"') are important!
In LaTeX:
...
Bla bla see Figure~\ref{figMyFigure}.
\begin{figure}[hbtp]
\begin{center}
% Scale the figure to have the height 80mm keeping
% the width/height ratio.
\resizebox{!}{80mm}{\includegraphics{myFigure.eps}}
\end{center}
\caption{The data used...}
\label{figMyFigure} % <-- NOTE: After \caption!
\end{figure}
...
This requires that you use "\usepackage{graphics}" or
"\usepackage{graphicx}" at the top your LaTeX document.
[This answer is a correction of my own answer in the "Re: [R] Latex
Question" thread from Dec 7, 2001:
http://www.r-project.org/nocvs/mail/r-help/2001/6836.html
where I forgot the argument 'horizontal=FALSE'.]
Good luck!
Henrik Bengtsson
Dept. of Mathematical Statistics @ Centre for Mathematical Sciences
Lund Institute of Technology/Lund University, Sweden (+2h UTC)
Office: P316, +46 46 222 9611 (phone), +46 46 222 4623 (fax)
h b @ m a t h s . l t h . s e
http://www.maths.lth.se/matstat/staff/hb/
On Thu, 7 Feb 2002, Robert Lundqvist wrote:
I have tried to find a neat way to include graphs from R in LaTeX documents, but have not succeeded (I work with a WinEdt/MikTeX combination). The two roads I have stumbled along so far are the following: *Generate postscript files and convert them into EPS files by means of GhostScript or other not so straightforward tools. *Generate pictex files and include these. None of these solutions have worked so far. I haven't spent so much time trying to find out what goes wrong, but since there might both LaTeX gurus and R wizards among you, I simply thought it would be better to lean on that expertize first. Any suggestions about how to achieve what really should be a simple task? --robert **************** Robert Lundqvist Dept of Quality Technology & Statistics Lulea University of Technology Sweden -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._