[R] xyplot (Lattice): Group order in display

Deepayan Sarkar deepayan.sarkar at gmail.com
Wed Sep 1 21:44:09 CEST 2010


On Wed, Sep 1, 2010 at 9:00 AM, jrflanders <jrflanders at gmail.com> wrote:
>
> Dear R users,
>
> I would like one of my groups in xyplot to appear to lie 'behind' the other
> groups. I have searched for help and find many, many topics about panel
> order (e.g., "as.table"), but that is not what I need.
>
> What is odd is that the group that I want to appear 'behind' the others
> (PROFILE) is the last in alphabetical order but xyplot is plotting it first.

Yes, the default order is alphabetical order (see ?factor). That group
is the last group, so is plotted last, and so appears on top.

> Any ideas?

You simply need to make it the first group, using something like

factor(TYPE, levels = ...)

-Deepayan


> Code:
> xyplot(Z_m~TEMP_C | LOCATION + EVENT, data = TC6,
>        groups = TYPE,
>        aspect = 2,
>        as.table = TRUE,
>        ylim = c(120,0),
>        between = list(y=2),
>        lty = 0,
>        strip = FALSE,
>        type = "o",
>        jitter.x = TRUE, jitter.y = TRUE,
>        pch = c(4,6,17,6,16), col.symbol =
> c("grey","blue","black","red","black"), cex = 1.2,
>        ylab = "Depth (m)",
>        xlab = expression(Temperature~"("~degree*C~")"),
>        scales = list(
>                y=list(at=seq(0,120,20), limits = c(120,0), cex = 1.2),
>                x=list(at=seq(3,18,3), alternating = c(2,1), limits =
> c(3,18), cex = 1.2)))
>
> Example data:
> EVENT, TRANSECT, LOC_CODE, TYPE, TEMP_C, Z_m
> 3 TC6 D MAX        15.6 1.2
> 3 TC6 D MEAN 14.8 1.1
> 3 TC6 D MIN        14.4 1.0
> 3 TC6 D POINT 11.3 55.8
> 3 TC6 D POINT 11.3 58.3
> 3 TC6 D POINT 11.3 58.3
> 3 TC6 D PROFILE 16.0 3.3
> 3 TC6 D PROFILE 16.0 3.2
> 3 TC6 D PROFILE 15.2 8.9
> 3 TC6 D PROFILE 12.6 14.8
> 3 TC6 D PROFILE 12.5 14.8
> 3 TC6 D PROFILE 11.6 21.2
> 3 TC6 D PROFILE 11.5 26.9
> 3 TC6 D PROFILE 11.4 33.3
> 3 TC6 D PROFILE 11.4 39.5
> 3 TC6 D PROFILE 11.3 45.4
> 3 TC6 D PROFILE 11.3 50.2
> 3 TC6 D PROFILE 11.3 54.1
> 3 TC6 D PROFILE 11.3 53.5
> --
> View this message in context: http://r.789695.n4.nabble.com/xyplot-Lattice-Group-order-in-display-tp2403483p2403483.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list