[R] main plot title

Rolf Turner r.turner at auckland.ac.nz
Fri Nov 30 05:36:46 CET 2007


On 30/11/2007, at 4:53 PM, marciarr wrote:

>
> Hello Rolf,
> I am sorry for the incovenience. Well, here it goes again!
> Let's say, I have a time series for the variable Chl. I wrote a  
> function
> "pgram" that gives me the raw periodogram of the time series. So, this
> function uses the values of my time series in an algorithm that  
> gives me new
> x and y values. And those are the coordinates that I am actually  
> using on
> the final plot function inside "pgram" (Chl is actually not an  
> argument of
> my plot function...). I am interested that the title of the  
> original dataset
> I used appears on my plot. Because I will use this function several  
> time
> series (let's say Chl and A, with different data sets), I would  
> like to
> obtain each time on the title of my plot for pgram(x), "Raw  
> periodogram of
> x" or for pgram(A), "Raw periodogram of A".
> Hope it is clearer now,

Not a lot, I'm afraid.  But I think I may be getting the idea ....

Here's an outline of my understanding of the situation:

	o you have a time series ``Chl''
	o you apply your home-grown function pgram() to it,

		pg.Chl <- pgram(Chl)

	o the result ``pg.Chl'' is a list with components ``x'' and ``y''
	(x being frequency and y being ``power'')

	o you now want to plot pg.Chl with another home-grown function,
	say my.pgram.plot(), and you want the name ``Chl'' to appear in
	the title of the plot.

Well --- for goodness sake! --- my.pgram.plot() has to be able to get  
the
information about that name from *somewhere*!  R, wonderful as it is, is
not psychic.

There are two obvious ways of doing this:  They have (obviously!) to be
effected back in the function pgram() which *does* have access to the
name ``Chl''.  If this information is not somehow enclosed in the object
pg.Chl, then there is no way for my.pgram.plot() to obtain this  
information.

Method 1:  Make the name of the ``power'' equal to ``Chl'' rather  
than ``y''.
You can do this making use of the deparse(substitute(<whatever>))  
technique
that Jim Holtman told you about.  There are various elaborations to this
idea --- e.g. you could make the name ``power.Chl'', and then extract  
the
``Chl'' bit by using gsub() or str.split() or substr() or ......

Method 2:  Give the object returned by pgram() a component or  
(probably better)
an attribute, called say ``dataname'' equal to the name of the time  
series
to which pgram() was applied.  Again, this name can be obtained via the
deparse(substitute(...)) technique.  You then write my.plot.pgram()  
so that
it extracts ``dataname'' from the object fed to it, and then uses  
dataname
to form the title.

The important thing to remember is that R has endless ways to store,  
manipulate,
and process information that is available to it, but it CANNOT magically
produce information that is not available to it.

		cheers,

			Rolf Turner

######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}



More information about the R-help mailing list