[R] Request for Help: remove zero in fraction from tick labe

(Ted Harding) ted.harding at wlandres.net
Sun Nov 6 16:18:05 CET 2011

On 06-Nov-11 14:50:18, David Winsemius wrote:
> On Nov 6, 2011, at 9:07 AM, Chee Chen wrote:
>> Dear All,
>> I would like to know how to do the following:
>> 1. suppose I have x values from the ordered from 0, 0.5, 1, and  
>> would like to label these three points on the x-axis.
>> 2. However, R labels them as 0.0, 0.5, 1.0. But I wan5 them to be  
>> 0, .5, 1, since the former way uses limited space of a multi-subgrap  
>> plot by adding extra zeros
> as.character(c(0, .5, 1))
> [1] "0"   "0.5" "1"
> I'm guessing that you are doing some sort of potting and using these  
> as axis labels but without code that remains a guess.
>> Thank you,
>> Chee

A general solution is exemplified by the code below.

Indications of how to do this (and other customisations)
by setting plot paramaters can be found in the output of


( and see also ?par). The code below is a modification
(and simplification) of the code for the final example
"##--- Log-Log Plot  with  custom axes" in ?plot.default.

x <- sort(runif(20,0,3))
y <- x^2
plot(x, y, type="o", pch='+', col="blue",
     main="Plot with custom axes", ylab="Y = X^2", xlab="X",
     axes = FALSE, frame.plot = TRUE)
x.at <- 0.5*(0:6)
axis(1, at = x.at, labels = formatC(x.at, format="fg"))
y.at <- (0:9)
axis(2, at = y.at, labels = formatC(y.at, format="fg"))

This sort of customisation does, however, usually require
that you tailor the details to the specific plot you are
drawing: in general, R can not be persuaded to get it
"right" automatically (in particular, you will need to
know the full ranges of the axes in order to get the
labels right).

Hoping this helps,

E-Mail: (Ted Harding) <ted.harding at wlandres.net>
Fax-to-email: +44 (0)870 094 0861
Date: 06-Nov-11                                       Time: 15:17:56
------------------------------ XFMail ------------------------------

More information about the R-help mailing list