If you really want to update the range of the plot axes after plotting, there is the zoomplot function in the TeachingDemos package. You will need to update the y-range each time through the loop and pass that to zoomplot. But, matplot is the better overall solution as has been pointed out already.
-- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 > -----Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- > project.org] On Behalf Of Servet Ahmet Cizmeli > Sent: Tuesday, October 27, 2009 12:13 PM > To: r-help@r-project.org > Subject: [R] automatically adjusting axis limits > > Dear R users, > > I am a newbie. Just switched from MATLAB. So thanks a lot for your > patience. > > I have 50000 spectra collected in field. Each spectra has two columns : > Wavelength (56) and the actual measurement. > > Each measurement came in a different .txt file on disk (50000 files in > total). I wrote a script that reads every spectra in a for loop and > constructs two variables : > > Wavelength (56) and Reflectance (56x50000). I would like to plot > Reflectance vs Wavelength i.e. overlay 50000 spectra one one top of the > other. > > plot(Wavelength, Reflectance) does not work (Matlab would do it): > > Error in xy.coords(x, y, xlabel, ylabel, log) : > 'x' and 'y' lengths differ > > > I then tried to construct the two matrices so that they have the same > size > (56x50000) and plot it all at once with the command "plot". This works > but > it is such a computationally inefficient way that I do not want to do > this > Why redundantly store wavelength data? Later I will have to process > much > more spectra so this is not a good practice for me. > > I then decided to draw the first spectra on the first run of the for > loop > with the command "plot" and add the subsequent graphs with the command > "lines". This works but the y-axes limits do not adjust automatically, > leaving many spectra out of the axis limits ;( > > I don't want to set the axis limits by hand as I need this script to be > completely autonomous. I don't want to program lines of code to > calculate > those limits myself either.... I am sure the mighty R can do it... BUT > HOW???? (Matlab would easily do it with a single command) > > What I need is a command that will redraw the graph by automatically > adjusting the axis limits. I have been searching for many days on the > web, > forums and mailing list archives but I still don't know how to do it. > Please help > > thanks a lot from advance for your kindly help > Servet > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.