[R] automatically adjusting axis limits

2009-10-27 Thread Servet Ahmet Cizmeli
Dear R users,

I am a newbie. Just switched from MATLAB. So thanks a lot for your
patience.

I have 5 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 (5 files in
total). I wrote a script that reads every spectra in a for loop and
constructs two variables :

Wavelength (56) and Reflectance (56x5). I would like to plot
Reflectance vs Wavelength i.e. overlay 5 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
(56x5) 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.


Re: [R] automatically adjusting axis limits

2009-10-27 Thread Ben Bolker



Sac-6 wrote:
 
 Dear R users,
 
 I am a newbie. Just switched from MATLAB. So thanks a lot for your
 patience.
 
 I have 5 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 (5 files in
 total). I wrote a script that reads every spectra in a for loop and
 constructs two variables :
 
 Wavelength (56) and Reflectance (56x5). I would like to plot
 Reflectance vs Wavelength i.e. overlay 5 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
 (56x5) 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
 
 

Are all the wavelengths the same?
The best answer is matplot(), but you need to reformat your data a bit.

for example:

files - list.files(pattern=[something appropriate])
datlist - lapply(files,read.table,...[other arguments such as header=TRUE])
wavelens - datlist[[1]][,1]
datlist2 - lapply(datlist,[[,vals]]  ## assuming second column is
called vals
datmat - do.call(datlist2,cbind)
matplot(wavelens,datmat)

-- 
View this message in context: 
http://www.nabble.com/automatically-adjusting-axis-limits-tp26082508p26083141.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] automatically adjusting axis limits

2009-10-27 Thread Ben Bolker



Sac-6 wrote:
 
 Dear R users,
 
 I am a newbie. Just switched from MATLAB. So thanks a lot for your
 patience.
 
 I have 5 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 (5 files in
 total). I wrote a script that reads every spectra in a for loop and
 constructs two variables :
 
 Wavelength (56) and Reflectance (56x5). I would like to plot
 Reflectance vs Wavelength i.e. overlay 5 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
 (56x5) 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
 
 

oops, I wasn't reading carefully enough, you've already done all the hard
work.

matplot(Wavelength,Reflectance)

-- 
View this message in context: 
http://www.nabble.com/automatically-adjusting-axis-limits-tp26082508p26083157.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] automatically adjusting axis limits

2009-10-27 Thread John Kane
PLEASE provide commented, minimal, self-contained, reproducible code.
 particularly a sample data.set.  At the moment it sounds like you have one 
variable (Wavelength) with a length of 56 and Reflectance with a length of 
5,000.  What format(s) are the data in?  Data.frames?

 Clearly this is not the case but I don't understand the data layout at all 


--- On Tue, 10/27/09, Servet Ahmet Cizmeli sa.cizm...@usherbrooke.ca wrote:

 From: Servet Ahmet Cizmeli sa.cizm...@usherbrooke.ca
 Subject: [R] automatically adjusting axis limits
 To: r-help@r-project.org
 Received: Tuesday, October 27, 2009, 2:12 PM
 Dear R users,
 
 I am a newbie. Just switched from MATLAB. So thanks a lot
 for your
 patience.
 
 I have 5 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
 (5 files in
 total). I wrote a script that reads every spectra in a for
 loop and
 constructs two variables :
 
 Wavelength (56) and Reflectance (56x5). I would like to
 plot
 Reflectance vs Wavelength i.e. overlay 5 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
 (56x5) 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.
 


  __
Looking for the perfect gift? Give the gift of Flickr! 

http://www.flickr.com/gift/

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


Re: [R] automatically adjusting axis limits

2009-10-27 Thread Greg Snow
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 5 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 (5 files in
 total). I wrote a script that reads every spectra in a for loop and
 constructs two variables :
 
 Wavelength (56) and Reflectance (56x5). I would like to plot
 Reflectance vs Wavelength i.e. overlay 5 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
 (56x5) 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.