[R] beamer overlays with Sweave?

Ben Bolker bbolker at gmail.com
Tue Mar 8 04:20:49 CET 2011


  This may be asking too much, but I'm wondering if anyone has a
solution (even a hack) for creating multiple (overlay) plots in an
Sweave file and post-processing the overlays in beamer appropriately.

  For example, suppose I have a series of figure blocks in my .Rnw file:

<<plot1,fig=TRUE>>=
[stuff]
@
<<plot2,fig=TRUE>>=
[stuff]
@
<<plot3,fig=TRUE>>=
[stuff]
@

  These three blocks create three figures that I want to have appear as
a series of overlays in the final PDF file.

  Sweave outputs the following LaTeX code:

\includegraphics{plot1}
\includegraphics{plot2}
\includegraphics{plot3}

  and I need to turn it into

\only<1>{\includegraphics{plot1}}
\only<2>{\includegraphics{plot2}}
\only<3>{\includegraphics{plot3}}

  I have few enough of these that I've been modifying them by hand
(couldn't easily come up with the appropriate sed/awk incantation); it
works, but it's annoying and error-prone.  I could spend some more time
hacking it, but I wondered if anyone else had already solved this ...

  (Brief googling of "beamer+Sweave+overlay" didn't find an obvious
answer, but I might have missed something ...)

  thanks
    Ben Bolker



More information about the R-help mailing list