[R] other than default labels in lattice plot

Petr Pikal petr.pikal at precheza.cz
Fri Feb 25 10:30:04 CET 2005


Thank you for quick answer Deepayan. I should have think of 
relabeling myself but this on the fly action is nice.

Thank you again.
Petr


On 24 Feb 2005 at 11:19, Deepayan Sarkar wrote:

> On Thursday 24 February 2005 08:03, Petr Pikal wrote:
> > Dear all
> >
> > I solved a problem of customised labels on strips and boxes in
> > bwplot by this construction.
> >
> > > bbb <- bwplot(zavoj ~ typmleti | pu)
> > > bbb$condlevels$pu <- c("Povrchová úprava", "Bez PU")
> > > bbb$x.limits <- c("Mleto", "Mleto a sítováno", "Nemleto")
> > > bbb
> >
> > but I wonder if some other easy option exist. Let say something like
> >
> > bwplot(zavoj~typmleti | pu,
> > some advanced stuff like
> > box.labels=c("Mleto", "Mleto a sítováno", "Nemleto"),
> > strip.labels =  c("Povrchová úprava", "Bez PU")
> > )
> 
> I think the most natural way to do this would be to change the labels
> of the factor levels directly. If you don't want to do this to your
> original data, you can do it on the fly as follows:
> 
> 
> relabel <- function(x, labels)
> {
>     stopifnot(is.factor(x))
>     levels(x) <- labels
>     x
> }
> 
> y <- rnorm(100)
> x <- gl(3, 1, 100)
> g <- gl(2, 1, 100)
> 
> bwplot(y ~ relabel(x, c("Mleto", "Mleto a sítováno", "Nemleto")) |
>        relabel(g, c("Povrchová úprava", "Bez PU")))
> 
> 
> Of course, you can also do it your way:
> 
> bwplot(y ~ x | g,
>        xlim = c("Mleto", "Mleto a sítováno", "Nemleto"),
>        strip = strip.custom(factor.levels =
>        c("Povrchová úprava", "Bez PU")))
> 
> This use of 'xlim' is a short-hand, the traditional way of changing
> the x-axis labels is 
> 
>        scales = list(x = list(labels = c("Mleto", "Mleto a sítováno",
>                                    "Nemleto")))
> 
> Changing strip labels is more complicated if you have more than one
> conditioning variable.
> 
> Deepayan

Petr Pikal
petr.pikal at precheza.cz




More information about the R-help mailing list