Re: [R] Change labels of x-axes in Plot of stl() function?

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Thu 08 Dec 2005 - 04:04:38 EST

One other thought. This can be arguably done more compactly using the proto package. We define a proto object consisting of three components:

and then run plot.stl in the scope of the proto object. There are two simplifications here:

  1. we don't need to do explicit manipulations of environments since proto automatically resets the environments of component functions. In particular, the environment of plot.stl is automatically reset to point to the proto object so that its scope is no longer the stats package.
  2. we don't need to redefine the argument list of plot.stl since with its environment automatically redefined as just explained, plot.stl will look for xlab in the proto object so we can just put it there rather than pass it in a new, different, argument list

library(proto)
STL <- proto(plot.stl = stats:::plot.stl,

	mtext = function(text, ...) graphics::mtext(xlab, ...),
	xlab = "time (decade)")

# test. First line computes stmd to be used as test data. example(stl)
with(STL, plot.stl(stmd))

# note that to change the xlab we can do this

STL$xlab <- "New xlab"
with(STL, plot.stl(stmd))

On 12/7/05, Gabor Grothendieck <ggrothendieck@gmail.com> wrote:
> If you look through the output of:
>
> stats:::plot.stl
>
> you see right near the end that "time" is hard coded in the call to mtext.
>
> However, we could temporarily redefine mtext so that it works as you
> wish and then redefine plot.stl so that it looks within the environment
> of our function to find mtext (rather than looking in the stats package):
>
> plot.stl <- function(..., xlab = "time") {
> mtext <- function(text, ...) graphics::mtext(xlab, ...)
> plot.stl <- stats:::plot.stl
> environment(plot.stl) <- environment()
> plot.stl(...)
> }
>
> # test it
> example(stl)
> plot.stl(stmd, xlab = "X")
>
>
>
> On 12/7/05, Jan Verbesselt <Jan.Verbesselt@biw.kuleuven.be> wrote:
> > Hi all,
> >
> > How can the label of the x-axes in the plot() of a stl.object be adapted?
> >
> > e.g.,
> >
> > When plotting: plot(stl(nottem, "per"))
> >
> > In the labels of the x-axes is "time". How can this be changed to e.g.,
> > "Time (dekade) "?
> >
> > It does not work with xlab or others anymore…
> >
> >
> >
> > Thanks,
> >
> > Jan
> >
> > _______________________________________________________________________
> > Ir. Jan Verbesselt
> > Research Associate
> > Biosystems Department ~ M³-BIORES
> > Vital Decosterstraat 102, 3000 Leuven, Belgium
> > Tel: +32-16-329750 Fax: +32-16-329760
> > http://gloveg.kuleuven.ac.be/
> > _______________________________________________________________________
> >
> >
> >
> >
> >
> > Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
> >
> >
> > [[alternative HTML version deleted]]
> >
> >
> >
> > ______________________________________________
> > R-help@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
> >
> >
>



R-help@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 Received on Thu Dec 08 04:16:53 2005

This archive was generated by hypermail 2.1.8 : Thu 08 Dec 2005 - 09:31:12 EST