[R] How to control the number format on plot axes ?

Sébastien pomchip at free.fr
Mon Aug 13 01:27:17 CEST 2007


Dear R-users,

Basically, everything is in the title of my e-mail. I know that some 
threads from the archives have already addressed this question but they 
did not really give a clear solution.
Here is a series of short codes that will illustrate the problem:

# First
a<-1:10
plot(x=a,y=a,log="y",type="p")

# Second
a<-1:10
myTicks<-c(1,2,5,10)
plot(x=a,y=a,log="y",type="p",yaxt="n")
axis(side=2,at=myTicks)

# Third
a<-1:10
myTicks<-c(0.1,1,2,5,10)
plot(x=a,y=a,log="y",type="p",yaxt="n")
axis(side=2,at=myTicks)

# Forth
a<-0.1:10
plot(x=a,y=a,log="y",type="p")

In the first and second examples, the plots are identical and the tick 
labels are 1, 2, 5 and 10. In the third, the labels are number in the 
x.0 format (1.0, 2.0, 5.0 and 10.0), even if there is no point below 1. 
The only reason I see is because the first element of myTicks is 0.1. 
And, the forth example is self-explanatory.
Interestingly, the 'scales' argument of xyplot in the lattice package do 
not add these (unnecessary) decimals on labels greater than 1.

Do you know how I could transpose the behavior of the lattice 'scales' 
argument to the 'axis' function ?

Thank you

PS: No offense, but please don't suggest I use lattice. I have to go for 
base R graphics in my full-scale project (it is a speed issue).



More information about the R-help mailing list