[R] Boxplot with Log10 and base-exponent axis

Steve Taylor steve.taylor at aut.ac.nz
Mon Jun 25 04:25:02 CEST 2012


This (and William's solution) is so good, I must ask:  
Is there a good reason why this is not the default functionality in the graphics package?  

The default displays the number 1 as 1+e00 which is hideous!

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Martin Maechler
Sent: Saturday, 23 June 2012 4:57a
To: Luigi; William Dunlap
Cc: r-help at r-project.org
Subject: Re: [R] Boxplot with Log10 and base-exponent axis


> The key is to supply an expression, not text, to the labels argument to axis.
> See help("plotmath") for details.  Here is an example:


>   x <- list(One=10^(sin(1:10)+5), Two=10^(cos(1:30)*2))
>   boxplot(x, log="y", yaxt="n")
>   ylim <- par("usr")[3:4]
>   log10AtY <- seq(ceiling(ylim[1]), floor(ylim[2]))
>   axis(side=2, at=10^log10AtY, lab=as.expression(lapply(log10AtY, function(y)bquote(10^.(y)))))

Yes, that's nice, and exactly the basic idea.

For a few years now,  the  eaxis() function in package "sfsmisc" 
does (something like) this (and a bit more) even more nicely :

 install.packages("sfsmisc")
 require("sfsmisc")

 x <- list(One=10^(sin(1:10)+5), Two=10^(cos(1:30)*2))
 boxplot(x, log="y", yaxt="n")
 eaxis(2)

--
Martin Maechler, ETH Zurich



More information about the R-help mailing list