Skip to content
Prev 393357 / 398500 Next

lattice: how to use a log scale on the x-axis with the bwplot function

... and here's a version where the x variable is different than y. It's
basically the same.


set.seed(123)
y <- runif(40,min=0, max= 10)
x <- seq(0,10, length = 40)
## 5 equally spaced groups labeled by log10 of the center
## of the intervals
xrng <- range(x)
eps <- .0001*c(-1,1)*diff(xrng) ## see ?cut
xrng <-xrng + eps
delta <- diff(xrng)/5 # 5 = number of intervals
brks <- seq(xrng[1], xrng[2],length.out =6)
labs <- round(log10(brks[-1] - delta/2), 2) ## log10 (centers)
groups <- cut(x,breaks = brks, ordered_result = TRUE,
              labels = paste0('10^',labs))
# creating the dataframe for the lattice functions
DF <- data.frame( y = y, groups = groups)

bwplot( y ~ groups
        , data=DF
        , scales = list(
           y = list(log=T)
        ),
)
On Sat, Dec 10, 2022 at 10:20 AM Bert Gunter <bgunter.4567 at gmail.com> wrote: