[R] Lattice xyplot to group by two parameters

Guy Jett GJett at itsi.com
Thu Jun 23 18:45:52 CEST 2011


My thanks to this mailing list and its members for their great help in the past.  I have yet another question per the following code and comments:

# I need individual graphs grouped by "PARLABEL" AND "Event", with "PARLABEL"
#   controlling pct and lty, and "Event" controlling col (where Event==1 is green
#   and Event==2 is red). This is attempted in the xyplot parameter
#   "groups = c(PARLABEL, Event)". Current behavior appears to be that the
#   colors are controlled by "PARLABEL" along with the shape and line type.  Some 
#   experimentation with those two parameters (reverse order, one or the other only)
#   suggests that the second parameter is ignored.
#
# I have also experimented with panel.superpose, subsetting, and Extended formula
#   interface, as appears to be suggested by the "man pages", but to no avail. 
#   
#   Note that I can get the graphics layout I need with ggplot2, but that has its
#   own issues with secondary axis and subtitle text placement, formatting, and 
#   pagination.
#
# Example script below.  Datafile included. 

  depthlimit=c(7,-1)
  xlimit=c(0.1,125000)
  TransectOrder = c("LLR19", "LLR18", "LLR17")

  OffsetOrder  =  c("T", "U", "V", "Y", "Z",
                    "A", "B", "C", "D", "E", "F", "G", "H")

# Parse the data for these plots ---------------------------------------------
  df <- read.csv(file = "5.04-r02_LTC-SE-SO-Compared.csv")
  df$Transect <- factor(df$Transect, levels = TransectOrder)
  levels(df$Transect)
  df$Offset <- factor(df$Offset, levels = OffsetOrder)
  levels(df$Offset)

    xyplot((sbd+sed)/2 ~ Result | Offset+Transect, groups = c(PARLABEL, Event),
      as.table = TRUE,
      drop.unused.levels = FALSE, data = df,
      layout = c(13,3), type = "b",
      xlim = c(0.01, 122000), ylim = depthlimit,
      pch  =c(16, 18), cex = c(1, 1), # to be controlled by "PARLABEL"
      lty  =c("dashed", "solid"),     # to be controlled by "PARLABEL"
      col = c("green", "red"),        # to be controlled by "Event"
      scales = list(alternating = 1, x = list(rot = 45, log = TRUE)))

Yours,
Guy Jett, R.G.
Project Geologist
ITSI,  A Gilbane Company
gjett at itsi.com



More information about the R-help mailing list