Re: [R] Labels on axes with log scales with lattice

From: Deepayan Sarkar <>
Date: Thu 18 Aug 2005 - 02:42:06 EST

On 8/14/05, Jamieson Cobleigh <> wrote:
> I using lattice to make some plots and I want to make the y-axis on
> some of these plots use a log scale. In the following plot:
> x <- 1:10
> y <- 2^x
> xyplot(log10(y) ~ x)
> I get tick marks on the y-axis at 0.5, 1.0, 1.5, 2.0, 2.5, and 3.0. I
> would rather have just 3 tick marks at 1.0, 2.0, and 3.0 but labeled
> 10, 100, and 1000.
> I know this can be done using the "at" and "labels" parameters to the
> "x" parameter to the "scales" parameter to the "xyplot" command.
> xyplot(log10(y) ~ x, scales=list(y=list(at=c(1, 2, 3), labels=c(10,
> 100, 1000))))
> My problem is that I am making multiple plots and cannot set the
> labels on each plot individually. I need to automate the computation
> of the "at" and "labels" parameters. I think the "axTicks" command
> can compute the information I need to set "at" and "labels" correctly,
> but I am having trouble determining how to set its parameters to make
> it compute the information I need. Perhaps "pretty" might work to,
> but "axTicks" seems better designed for handling logarithmic axes.
> Does anyone have any suggestions?

The `right' way to do this is

xyplot(y ~ x, scales = list(y = list(log = 10)))

Unfortunately, the labeling for this doesn't use axTicks, it takes the easy way out by using labels of the form "10^2", "10^3", etc. This is partly due to laziness on my part, and also the fact that axTicks doesn't support all the features 'scales' claims to.

My intended `solution' to this (currently vapourware) is to allow the user to specify a function to calculate tick positions and labels. In principle, this could be useful for other transformations, e.g. sqrt for rootograms. I haven't thought through what the API for this would be like, and I don't know when I will get around to actually implementing it.

Deepayan mailing list PLEASE do read the posting guide! Received on Thu Aug 18 02:47:18 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 15:27:33 EST