Re: [R] Axis/Ticks/Scale

From: Martin Maechler <maechler_at_stat.math.ethz.ch>
Date: Fri 30 Dec 2005 - 08:06:42 EST

>>>>> "Marc" == Marc Schwartz (via MN) <mschwartz@mn.rr.com> >>>>> on Wed, 28 Dec 2005 15:46:37 -0600 writes:

    Marc> On Wed, 2005-12-28 at 20:15 +0000,     Marc> R.C.GILL@soton.ac.uk wrote:
>> Dear All,
>>
>> Apologies for this simple question and thanks in advance
>> for any help given.
>>
>> Suppose I wanted to plot 1 million observations and
>> produce the command
>>
>> plot(rnorm(1000000))
>>
>> The labels of the xaxis are 0, e+00 2 e+05 etc. These are
>> clearly not very attractive (The plots are for a
>> PhD. thesis).
>>
>> I would like the axes to be 0,2,4,6,8,10 with a *10^5 on
>> the right hand side.
>>
>> Is there a simple command for this?
>>
>> Best Wishes
>>
>> Roger

    Marc> See ?plotmath for some additional examples and there     Marc> are some others in the list archives.

Yes, I think this one is there too:
It has the "* 10^k" after each number;
the nice thing about it is that it works for all kind of data -- and of course, in principle it could be built into R ...

###----------------- Do "a 10^k" labeling instead of "a e<k>" ---

axTexpr <- function(side, at = axTicks(side, axp=axp, usr=usr, log=log),
                    axp = NULL, usr = NULL, log = NULL)
{
    ## Purpose: Do "a 10^k" labeling instead of "a e<k>"
    ##	      this auxiliary should return 'at' and 'label' (expression)
    ## ----------------------------------------------------------------------
    ## Arguments: as for axTicks()
    ## ----------------------------------------------------------------------
    ## Author: Martin Maechler, Date:  7 May 2004, 18:01
    eT <- floor(log10(abs(at)))# at == 0 case is dealt with below
    mT <- at / 10^eT
    ss <- lapply(seq(along = at),
                 function(i) if(at[i] == 0) quote(0) else
                 substitute(A %*% 10^E, list(A=mT[i], E=eT[i])))
    do.call("expression", ss)
}

x <- 1e7*(-10:50)
y <- dnorm(x, m=10e7, s=20e7)

plot(x,y)
## ^^^^^^ not so nice; ok, try 

par(mar=.1+c(5,5,4,1))## << For the horizontal y-axis labels, need more space plot(x,y, axes= FALSE, frame=TRUE)
aX <- axTicks(1); axis(1, at=aX, label= axTexpr(1, aX)) if(FALSE) # rather the next one
{ aY <- axTicks(2); axis(2, at=aY, label= axTexpr(2, aY))} ## or rather (horizontal labels on y-axis): aY <- axTicks(2); axis(2, at=aY, label= axTexpr(2, aY), las=2)



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 Fri Dec 30 08:13:17 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:41:44 EST