Sklyar, Oleg (MI London)
2008-Apr-07 11:22 UTC
[Rd] Overriding axis formatting with custom Axis method, Axis.numeric etc
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
Henrique Dallazuanna
2008-Apr-07 11:49 UTC
[Rd] Overriding axis formatting with custom Axis method, Axis.numeric etc
I think that you can change the axis as a argument in plot: custom.axis <- bquote({axis(1, col="red", lwd=5) axis(2, col="red", lwd=5)}) suppressWarnings(plot(1:5, 1:5, frame.plot = eval(custom.axis))) suppressWarnings(plot(1:5, frame.plot = eval(custom.axis))) On Mon, Apr 7, 2008 at 8:22 AM, Sklyar, Oleg (MI London) < osklyar@maninvestments.com> wrote:> 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@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 > > ______________________________________________ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
Prof Brian Ripley
2008-Apr-07 12:01 UTC
[Rd] Overriding axis formatting with custom Axis method, Axis.numeric etc
On Mon, 7 Apr 2008, Sklyar, Oleg (MI London) wrote:> 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?Axis() is an S3 generic, not an S4 generic, so it does not make sense to me to talk about 'signatures'. It is in the graphics namespace, so you cannot redefine it for use by plot.default. methods("Axis") answers what I think you meant to ask.> 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.Try debug(Axis) and see what it is called with. (I have altered that in current versions of R -- you didn't say what yours was.)> 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)Namespaces ... (perhaps you need to study them?). -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Gabor Grothendieck
2008-Apr-07 12:09 UTC
[Rd] Overriding axis formatting with custom Axis method, Axis.numeric etc
Try this: Axis.AsIs = 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) } plot(I(1:10)) On Mon, Apr 7, 2008 at 7:22 AM, Sklyar, Oleg (MI London) <osklyar at maninvestments.com> wrote:> 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 > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >
Reasonably Related Threads
- particulars of importing/loading libraries
- graphics::Axis loosing S3/S4 class attributes of 'x' in 2.7.0 RC
- setClassUnion with numeric; extending class union
- likely bug in 'serialize' or please explain the memory usage
- ISOdate/ISOdatetime performance suggestions, other date/time questions