The problem seems to be that your boxplots are based on log10
of value
, whereas the axis you are drawing uses the original values. There are two ways to fix this. Either use log10
to generate your axis ticks, or else use log="y"
when you generate your boxplots to do the coordinate transformation. Here is an illustration with some sample data:
set.seed(123)
x<-sample(100,1000,T)
var<-sample(letters[1:5],1000,T)
Choice number 1:
boxplot(log10(x) ~ var,yaxt="n")
axis(side=2,labels=round(10^(seq(log10(min(x)),log10(max(x)),len=5)),2),at=seq(log10(min(x)),log10(max(x)),len=5))
Choice number 2:
boxplot(x ~ var,yaxt="n",log="y")
axis(side=2,labels=seq(min(x),max(x),len=5),at=seq(min(x),max(x),len=5))
You can get the ticks to be spaced logarithmically or linearly with either method by specifying the at
parameter appropriately, for example, this command will place evenly spaced tick marks on a plot generated with log="y"
:
axis(side=2,labels=round(exp(seq(log(min(x)),log(max(x)),len=5)),2),at=exp(seq(log(min(x)),log(max(x)),len=5)))