[R] Fixed/ trellis/ panel.superpose/ passing in superscripts/ groups

McClatchie, Sam (PIRSA-SARDI) mcclatchie.sam at saugov.sa.gov.au
Wed Mar 16 06:31:59 CET 2005


Background:
OS: Linux Mandrake 10.1
release: R 2.0.0
editor: GNU Emacs 21.3.2
front-end: ESS 5.2.3
---------------------------------
Colleagues

I have solved the miscoding with subscript and groups in panel.superpose. I
was neglecting to pass in the variables correctly.

"sardine.egg.T.S.space.2001.and.2002.exp" <-
  function()
  {
    library(lattice)
    library(grid)
    ##     trellis.device(postscript,
    ##
file="../figures/sardine.egg.T.S.space.2001.and.2002.ps",
    ##                  horizontal=FALSE, color=TRUE)
    
    year <- as.factor(rep(2001,  dim(mn.ts.e.2001)[1]))    
    year.2001 <- cbind(mn.ts.e.2001,year)
    year <- as.factor(rep(2002,  dim(mn.ts.e.2002)[1]))    
    year.2002 <- cbind(mn.ts.e.2002,year)    
    mn.ts.e.both <- rbind(year.2001, year.2002)
                                        #browser()    
###trellis plot
    ## define conditioning interval
    int <- matrix(c(0,2,3,4,5,8,9,16,17,32,33,64), ncol=2, byrow=TRUE)
    egg.counts <- shingle(mn.ts.e.both$eggs2.Pilch.Eggs, intervals = int)
    ##larvae.counts <- shingle(mn.ts.e.both$eggs2.Pilch.Larv, intervals =
int)
    ## define plot structure
    out1 <- xyplot(mn.t ~  mn.s |  egg.counts,
                   data = mn.ts.e.both,
                   groups = year,
                   xlim = c(35,38), ylim = c(12,24),
                   xlab = "mean salinity", ylab = "mean temperature (deg.
C)",
                   main = "2001 and 2002 egg densities in
Temperature-Salinity space",
                   aspect = "xy",
                   jitter = T,
                   layout = c(1,6),
                   auto.key=TRUE,
                   ##add to individual panels
                   panel = function(x, y, subscripts, groups){
                     ## plot all the T-S data for both years
                     ## using explicit variables, differing from x,y
                     panel.xyplot(data.2001$Salinity,
data.2001$Temperature.oC, 
                                  pch=".", col="yellow");
                     panel.xyplot(data.2002$Salinity,
data.2002$Temperature.oC, 
                                  pch=".", col="orange");
                     ## add some labels for watermasses
                     panel.text(37.8, 15, "Upwelling");
                     panel.text(37.8, 17.5, "Warm pool");
                     panel.text(37.8, 19.75, "Shelf break");
                     panel.text(37.8, 21.5, "Spencer Gulf");
                     panel.abline(h = c(16,19,20.5), v = 36.5, col="red",
lty=2);
                     ## overlay the conditioned egg data on the TS plots
                     panel.superpose(x, y, subscripts, groups);
                     ## add a legend
                     auto.key = T
                   }
                   )

    print(out1)
    ##   graphics.off()
    
  }

----
Sam McClatchie,
Biological oceanography 
South Australian Aquatic Sciences Centre
PO Box 120, Henley Beach 5022
Adelaide, South Australia
email <mcclatchie.sam at saugov.sa.gov.au>
Telephone: (61-8) 8207 5448
FAX: (61-8) 8200 2481
Research home page <http://www.members.iinet.net.au/~s.mcclatchie/>
  
                   /\
      ...>><xX(°> 
                //// \\\\
                   <°)Xx><<
              /////  \\\\\\
                        ><(((°> 
  >><(((°>   ...>><xX(°>O<°)Xx><<




More information about the R-help mailing list