[R] plotting a 1000 plots?

jasont@indigoindustrial.co.nz jasont at indigoindustrial.co.nz
Thu May 23 01:06:38 CEST 2002


> I would like to plot lots of plots (2x2 plots) of a set of data for many
> sets. I can do it just fine for one set of data, but I would like to
> generate a small mountain of plots for others to examine. Basically, I would
> like to generate the same par( mcol=c(2,2) ) plot for about 1000 datasets.

I do exactly this with Sweave(), where dozens of reports are run nightly 
that number into the hundreds of pages per report.

library(tools)
help(Sweave)

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

(Free advice - if you're going to do 1000s of plots per run, and you're
not familiar with try(), get familiar it, to avoid Great Anguish <tm>).

I do this by making a temporary directory,  loop over a list of report titles, 
and have Sweave() produce a separate report for each into that temporary 
directory (you wind up with lots of self-contained .tex files).
I then run a perl script over every .tex file in the directory, collating 
them into one big .tex file.  The perl script is really quite simple (see 
below).  A good perl hacker could do a much better job;  I still
program perl like a mediocre C hacker.

Sweave produces eps and pdf versions of the plots, so running 
pdflatex directly is also an option, rather than 
LaTeX + eps -> dvi + dvipdfm -> pdf.

Sweave is a very, very good utility.  It's an amazing 
combination - typesetting by LaTeX, and calculations and graphics 
by R, handled seamlessly together, usually while I'm alseep, as the 
reports are run overnight.

Thanks, Fredrich!  

Cheers

Jason

collate.pl:

#!/usr/bin/perl -w
#
##########################
# collate.pl #############
#
# DESCRIPTION ############
# Take multiple LaTeX files, and combine them into one.
# Assume that the first preamble is identical throughout.
#
# On the first file, everything is printed, except the
# \end{document}.
#
# After the first file is read, only the portions
# between \begin{document} and \end{document}
# are printed.  \tableofcontents and \listoffigures
# are also omitted from subsequent files.
#
# ARGUMENTS ##############
# 1..n) files to collate.  reads from stdin if none specified.
#

my $printThis = 1; #true if we're to print the preamble
my $toc = 0; #true if we've already printed \tableofcontents
my $lof = 0; #true if we've already printed \listoffigures

while(<>){
        if($toc && $_ =~ /\\tableofcontents/) {
                $_ =~ s/\\tableofcontents//;
        }
        if($lof && $_ =~ /\\listoffigures/) {
                $_ =~ s/\\listoffigures//;
        }
        if(!$printThis) {
                if($_ =~ m/\\begin{document}/) {
                        $_ =~ s/\\begin{document}//;
                        $printThis = 1;
                }
        }
        if($printThis) { #if we're on the first file
                if($_ !~ /\\end{document}/ ) { #print all lines that don't
                        print;                #contain \end{document}
                } else {
                        print;  #if they do, strip out \end{document}
                        $printThis = 0;
                }
        }
        if($_ =~ /\\tableofcontents/) {
                $toc = 1;
        }
        if($_ =~ /\\listoffigures/) {
                $lof = 1;
        }
}

print "\\end{document}\n";



-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list