[R] How to control the number format on plot axes ?
jholtman at gmail.com
Mon Aug 13 02:30:23 CEST 2007
Here is a way that you can put the formatting that you want; you were
not clear on exactly what you were after. You can setup the 'labels'
argument for whatever you want.
# set ylim to range of myTicks that you want
# change the sprintf to whatever formatting you want
labels=ifelse(myTicks >= 1, sprintf("%.0f", myTicks),
On 8/12/07, Sébastien <pomchip at free.fr> wrote:
> 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
> # Second
> # Third
> # Forth
> 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).
> R-help at stat.math.ethz.ch mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
+1 513 646 9390
What is the problem you are trying to solve?
More information about the R-help