[R] automatically adjusting axis limits

Servet Ahmet Cizmeli sa.cizmeli at usherbrooke.ca
Tue Oct 27 19:12:35 CET 2009


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




More information about the R-help mailing list