Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I place all sweave figures at the end of the document?

Tags:

r

latex

sweave

I have a LaTeX manuscript that inputs from a single Sweave file. The file creates plots and places them in the document using <fig=TRUE>.

Is there a way that I can tell all of the figures to go to the end of the document, where the rest of the figures are? All of the other figures are placed at the end with the LaTeX option [ht!]

The only solution I have come up with is to use <fig=FALSE>, save the file as a graphics file, and then call the figure from within LaTeX at the end of the document. Is there a way to do this within the R-code part of the Sweave document itself (presumably this would be easier to do).

like image 220
Abe Avatar asked Nov 01 '11 20:11

Abe


3 Answers

Another alternative is to use the LaTeX 'endfloat' package. Add the following to your preamble, and it will put all of the figures at the end.

\usepackage[noheads,nomarkers]{endfloat}
like image 156
David LeBauer Avatar answered Oct 01 '22 14:10

David LeBauer


You could also do <chunk_name, fig = TRUE, include = F> in the chunk where you create the plot and call it at the end using

<new_chunk, fig = TRUE> <<chunk_name>> @

like image 43
Ramnath Avatar answered Oct 01 '22 16:10

Ramnath


The image created with fig=TRUE will always have the name: FILENAME-CHUNKNAME.pdf

Where FILENAME is the name of your .Rnw file without extension, So with this you can easilly make the includegraphics call yourself:

% Somewhere in source:
<<CHUNKNAME,fig=TRUE,include=FALSE>>=
plot(1)
@

% Later in source:
\begin{figure}
\centering
\includegraphics{FILENAME-CHUNKNAME}
\caption{Whatever}
\label{fig:whatever}
\end{figure}
like image 25
Sacha Epskamp Avatar answered Oct 01 '22 15:10

Sacha Epskamp