Reputation: 25
I'd like to put my own labels on a log-transformed y-axis of a boxplot:
with(TX, boxplot(b~tx, ylab="Biomass, g/m2, ln", yaxt="n", las=2, log="y", cex.axis=0.7))
The data:
pretty(log(TX$b))
[1] -6 -4 -2 0 2 4 6
length(levels(TX$tx))
[1] 22
I tried:
axis(2, at=pretty(log(TX$b)), labels=pretty(log(TX$b))) and
axis(2, at=c(-6, -3, -1, 0, 1, 3, 6), labels=c(-6, -3, -1, 0, 1, 3, 6)),
but in both cases only the positive values (and corresponding ticks!) are displayed. What's the reason and how do I get this fixed?
Upvotes: 1
Views: 162
Reputation: 115445
You have transformed the y variable in the call to plot using log = 'y'
.
This means you pass the at
component as values on the untransformed scale.
axis(2, at= exp(c(-6, -3, -1, 0, 1, 3, 6)), labels=c(-6, -3, -1, 0, 1, 3, 6))
A reproducible example
set.seed(1)
TX <- data.frame(tx = gl(2,3), y= rlnorm(600, mean = -1, sd = 3))
boxplot( y~tx, data = TX, log = 'y',yaxt="n", las=2, cex.axis=0.7)
axis(2, at= exp(c(-6, -3, -1, 0, 1, 3, 6)), labels=c(-6, -3, -1, 0, 1, 3, 6))
Upvotes: 1