[R] expression exponent labeling

Gerrit Eichner Gerrit.Eichner at math.uni-giessen.de
Wed Mar 13 14:37:33 CET 2013


Hi, Berry,

I think

> for(i in -8:-3) axis(1, i, substitute(10^j, list( j = i)))

achieves what you want.

  Regards --  Gerrit


On Wed, 13 Mar 2013, Berry Boessenkool wrote:

>
>
> Hi all,
>
> I want to label an axis with exponents, but can't get it done with expression.
> Any hints would be very welcome!
>
> # simulated data, somewhat similarly distributed to my real data:
> set.seed(12); d <- rbeta(1e6, 0.2,2)*150 ; d <- d[d>1e-8]
> hist( d  , breaks=100)
> # now on a logarithmically scaled axis:
> hist(log10(d), breaks=100, xaxt="n")
> abline(v= log10(1:10*10^rep(-9:3, each=10)), col="darkgrey" ); box()
> hist(log10(d), breaks=100, col="forestgreen", add=T)
> axis(1, log10(1:10*10^rep(-9:3, each=10)), labels=F)
> axis(1, -2:2, format(10^(-2:2), scient=3, drop0trailing=T) )
> # the labels with lower values should be in the form of 10^x:
> axis(1, -8:-3, expression( 10^(-8:-3)) )# doesn't work, because expression returns only one output
> for(i in -8:-3) axis(1, i, expression(10^i)  ) # writes i at all locations
>
> expression does exactly what it should, but I want something different here...
> I've tried I(10^i) instead, but that's not right either.
>
> Thanks ahead,
> Berry
>
>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


More information about the R-help mailing list