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
> 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.Although I have not done this with beamer and overlays before, I once had to resort to generating the includegraphics commands from within a loop in order to save substantial amoutns of typing. You could do something similar along these lines (untested): <<echo=F>> slidenum <- 1 plotbasename <- "something" plotfilename <- paste(plotbasename, slidenum, ".pdf", sep="") pdf(file=plotfilename) plot(stuff) dev.off() cat("\\only", slidenum, "{\includegraphics{", plotfilename ,"}}\n" ,sep="") @ <<echo=F>> slidenum <- slidenum + 1 plotfilename <- paste(plotbasenema, slidenum, ".pdf", sep="") pdf(file=plotfilename) plot(stuff) dev.off() cat("\\only", slidenum, "{\includegraphics{", plotfilename ,"}}\n" ,sep="") @ If you want toget really fancy, you could wrap most of this in a conveniance function... cu Philipp -- Dr. Philipp Pagel Lehrstuhl f?r Genomorientierte Bioinformatik Technische Universit?t M?nchen Wissenschaftszentrum Weihenstephan Maximus-von-Imhof-Forum 3 85354 Freising, Germany http://webclu.bio.wzw.tum.de/~pagel/
Oops - have to comment my own answer:> <<echo=F>>For this to work it needs to be <<echo=F, results=tex>> cu Philipp -- Dr. Philipp Pagel Lehrstuhl f?r Genomorientierte Bioinformatik Technische Universit?t M?nchen Wissenschaftszentrum Weihenstephan Maximus-von-Imhof-Forum 3 85354 Freising, Germany http://webclu.bio.wzw.tum.de/~pagel/
I don't have an example to hand, but check out the animation package. I have been able to include animations in pdf documents using this and it worked really well - and I think it works with sweave too. I think you could set it up to allow the user to press a button to go through each graphic in turn (rather than a continuous 'movie') - which would mimic the overlay effect in beamer. Worth looking at, because it would then be possible to make some genuine "dynamic" documents. Must have a look myself... All the best. David -- View this message in context: http://r.789695.n4.nabble.com/beamer-overlays-with-Sweave-tp3340570p3341112.html Sent from the R help mailing list archive at Nabble.com.
On 11-03-07 10:20 PM, Ben Bolker wrote:> > 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 ...)You can put the \only calls in the Rnw, e.g. \only<1>{ <<fig=true>>m <- 1 <<plotchunk>> @ } \only<2>{ <<fig=true>>m <- 2 <<plotchunk>> @ } Duncan Murdoch