[R] lattice: limits in reversed order with relation="same"
Deepayan Sarkar
deepayan.sarkar at gmail.com
Mon Aug 30 12:37:59 CEST 2010
On Mon, Aug 30, 2010 at 3:57 PM, Thaler, Thorn, LAUSANNE, Applied
Mathematics <Thorn.Thaler at rdls.nestle.com> wrote:
> Hi everybody,
>
> I want an x-axis which has xlim=c(max, min) rather than xlim=c(min, max)
> in order to reflect the type of the process (cooling):
>
> library(lattice)
> myprepanel <- function(x,y,...) list(xlim=rev(range(x)))
> x <- rep(1:10, 100)
> z <- factor(sample(10, 1000, T))
> y <- rnorm(1000, x, as.numeric(z))
>
> xyplot(y~x|z, scales=list(x="free"), prepanel=myprepanel)
>
> This works as expected. But I don't like to have the x-axis annotation
> in every panel since in fact it is the same in every panel. Doing the
> same with relation="same" does not work, however. From "Lattice -
> Multivariate Data Visualization with R" p.142:
>
> "Note that this will not work when relation="same", because in that case
> the process of combining limits from different packets makes the final
> limit sorted [...]"
>
> So which part do I have to change to get a multipanel plot with x-axis
> in reversed order but where the x-axes are only drawn in the panels at
> the boundary (like in xyplot(y~x|z))? Do I have to provide an own axis
> function?
No (in fact that wouldn't work anyway), you can simply do
xyplot(y~x|z, xlim = rev(extendrange(x)))
The point is that in this case you have to explicitly specify a
pre-computed limit, and cannot rely on the prepanel function to give
you a nice default.
-Deepayan
More information about the R-help
mailing list