[R] plotting with multiple files

Matt Austin threehounds at operamail.com
Tue Oct 12 05:08:05 CEST 2004


T. Murlidharan Nair <nair <at> sdsc.edu> writes:

> 
> Hi !!
> I need to generate plots from several multiple file and I am doing this 
> by reading it as a list using c(file1, file2.....).
> Since I need to either print the plots or save it as an plot image while 
> generating  the plots in a loop, has anyone
> done this before. Also is there a getchar() equivalent in R, I mean just 
> to wait for an input from the console so that
> I can print before it plots the next plot.
> Thanks ../Murli
> 
> ______________________________________________
> R-help <at> stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
> 
> 


The first example directs output to tmp.pdf while the second waits for 
input "y".  The fun() function throws an error if anything but "y" is input and 
ends execution (not pretty).

tempDat <- lapply( 1:10, function(x) list( x= rnorm(10), y = rnorm(10)))

pdf( "tmp.pdf" )
  lapply( tempDat , function( inDat ){

    plot( inDat$x, inDat$y )

  } )
dev.off()


fun <- function() {
  ANSWER <- readline("Next Plot (y=continue else break)")
  if (substr(ANSWER, 1, 1) != "y")
    stop("Ending routine\n")
}
lapply( tempDat , function( inDat ){

    plot( inDat$x, inDat$y )
    fun()

  } )




More information about the R-help mailing list