Skip to content

Request for Help: remove zero in fraction from tick labeling

3 messages · Chee Chen, David Winsemius, (Ted Harding)

#
On Nov 6, 2011, at 9:07 AM, Chee Chen wrote:

            
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.
David Winsemius, MD
West Hartford, CT
#
On 06-Nov-11 14:50:18, David Winsemius wrote:
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

  ?plot.default

( 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,
Ted.

--------------------------------------------------------------------
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 ------------------------------