[Rd] Overriding axis formatting with custom Axis method, Axis.numeric etc
Sklyar, Oleg (MI London)
osklyar at maninvestments.com
Mon Apr 7 13:22:36 CEST 2008
Dear list:
I would like to override the default way R formats plot axes with a
custom method(s). Obviously I would prefer to define it as general as
possible avoiding writing a custom method for each individual class
where possible.
The plot.default method (and I assume other methods as well) calls
Axis(...) to produce the axis layout depending on data. In this sense it
seems reasonable to (re)define Axis methods rather than change plot
methods (which are impossible to control as there can be too many custom
ones).
Now my question is how can I redefine Axis that it is automatically
called by plot.default and other plot methods? Or which Axis-method
signatures are already defined that I should redefine?
What I have succeeded so far was defining Axis.numeric and Axis.myClass,
which are called by default if I supply data of class numeric or
myClass. For example, a simple code like
Axis.numeric = AxisFUN = function(x=NULL, at=NULL, ..., side,
labels=TRUE) {
if (is.null(at)) at = pretty(x)
axis(at=at, ..., side=side, labels=labels, col="red", lwd=5)
}
run with plot(1:5,1:5) will format both axes red.
However, if I execute it with plot(1:5) only x axis plotting is
intercepted leaving y at default formatting although it is also numeric.
Why and what should I define to intercept for plotting the y axis or for
plotting axes in boxplot etc. Simply importing and overriding Axis as
function does not bring anything, it wouldn't get called.
Also I was not able to use S4 methods to redefine Axis. Overriding it
with the code from above using any of the following signatures also
didn't work for me - they are simply ignored:
setGeneric("Axis")
setMethod("Axis", signature(x="missing",at="numeric"), AxisFUN)
setMethod("Axis", signature(x="numeric",at="missing"), AxisFUN)
setMethod("Axis", signature(x="missing",at="ANY"), AxisFUN)
setMethod("Axis", signature(x="ANY",at="missing"), AxisFUN)
setMethod("Axis", signature(x="ANY",at="ANY"), AxisFUN)
Any ideas?
Thanks,
Oleg
Dr Oleg Sklyar
Technology Group
Man Investments Ltd
+44 (0)20 7144 3803
osklyar at maninvestments.com
**********************************************************************
The contents of this email are for the named addressee(s) only.
It contains information which may be confidential and privileged.
If you are not the intended recipient, please notify the sender
immediately, destroy this email and any attachments and do not
otherwise disclose or use them. Email transmission is not a
secure method of communication and Man Investments cannot accept
responsibility for the completeness or accuracy of this email or
any attachments. Whilst Man Investments makes every effort to keep
its network free from viruses, it does not accept responsibility
for any computer virus which might be transferred by way of this
email or any attachments. This email does not constitute a request,
offer, recommendation or solicitation of any kind to buy, subscribe,
sell or redeem any investment instruments or to perform other such
transactions of any kind. Man Investments reserves the right to
monitor, record and retain all electronic communications through
its network to ensure the integrity of its systems, for record
keeping and regulatory purposes.
Visit us at: www.maninvestments.com
More information about the R-devel
mailing list