On 2013-03-13 06:37, Gerrit Eichner wrote:
Hi, Berry,
I think
for(i in -8:-3) axis(1, i, substitute(10^j, list( j = i)))
achieves what you want.
Regards -- Gerrit
Here's another (really no different) solution:
for(i in -8:-3) axis(1, i, bquote(10^.(i)))
For more flexibility, if you need to do this a lot, you could
create an "expression" vector:
x <- -8:-3
z <- vector("expression", 6)
for(i in 1:6) z[[i]] <- bquote(10^.(x[i]))
axis(1, x, z)
Peter Ehlers
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@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.