[R] Lattice graphics strip labels for shingles

From: Kiermeier, Andreas (PIRSA - SARDI) <Kiermeier.Andreas_at_saugov.sa.gov.au>
Date: Tue 18 Oct 2005 - 16:02:51 EST


Dear all,

back in 2002 Martin Henry H. Stevens wrote (https://stat.ethz.ch/pipermail/r-help/2002-May/019851.html)

> How do I control the text in strips? Specifically, I want to put in the
> ranges generated in shingle(x) where x is continuous.

with an answer from Deepyan Sarkar (see strip.new towards the end of this message). I assume that the answer worked back then, but I've tried to implement it today, with little success. I think that it may have to do with namespaces - but I'm not sure.

Here is the code I used after creating the strip.new function (in .GlobalEnv).

> x1 <- rnorm(100)
> x2 <- rnorm(100)
> x3 <- rnorm(100)
>
> br <- matrix(c(seq(-3, 3, by=0.5), seq(-3, 3, by=0.5)+0.5), ncol=2,
byrow=FALSE)
>
> x3.sh <- shingle(x3, intervals=br)
>
> xyplot(x1 ~ x2 | x3.sh,

+        strip=function(shingle.intervals,...)
+        strip.new(shingle.intervals=br, ...))
Error in strip.new(shingle.intervals = br, ...) : 
	couldn't find function "grid.rect"

I realize that there have been changes in strip.default since then, but even attempting to create my own (modified) version of it (in .GlobalEnv) comes up with a similar error, namely

Error in strip.default(shingle.intervals = br, ...) :

        couldn't find function "pushViewport"

Any help would be greatly appreciated - please reply directly to me as I am not currently on the list.

Regards,

Andreas

strip.new <-

    function(which.given,

             which.panel,
             var.name,
             factor.levels,
             shingle.intervals,
             strip.names = c(FALSE, TRUE),
             style = 1,
             bg = trellis.par.get("strip.background")$col[which.given],
             fg = trellis.par.get("strip.shingle")$col[which.given],
             par.strip.text = trellis.par.get("add.text"))
{

    name <- var.name[which.given]
    level <- which.panel[which.given]
    strip.names <- rep(strip.names, length = 2)     

    if (is.null(factor.levels)) { # means this is a shingle, as opposed to a

     
                                  ## factor
        if (is.null(shingle.intervals)) 
           stop("both factor.levels and shingle.intervals cannot be NULL")

        strip.names <- strip.names[2]
        grid.rect(gp = gpar(fill=bg))
        t <- range(shingle.intervals)
        r <- (range(shingle.intervals[level,])-t[1])/diff(t)
        grid.rect(x = unit(r%*%c(.5,.5),"npc"), width = unit(diff(r),"npc"),
                  gp = gpar(col=fg, fill=fg))
        if (strip.names) grid.text(label = paste(shingle.intervals[level,1],
                                   shingle.intervals[level, 2], sep = ' ,
'),
                                   gp = gpar(col = par.strip.text$col,
                                   font = par.strip.text$font,
                                   fontsize = par.strip.text$cex *
                                   current.viewport()$gp$fontsize))
        
        grid.rect()

    }
    else strip.default(which.given,
                       which.panel,
                       var.name,
                       factor.levels = factor.levels,
                       shingle.intervals = shingle.intervals,
                       strip.names,
                       style,
                       bg,
                       fg,
                       par.strip.text)

}

Dr Andreas Kiermeier
Statistician
SARDI FOOD SAFETY PROGRAM 33 Flemington Street
Glenside SA 5065
Ph:	+61 8 8207 7884
Fax:	+61 8 8207 7854
Mob:	0423 028 565

Email: Kiermeier.Andreas@saugov.sa.gov.au


The information in this e-mail and attachments (if any) may be confidential and/or legally privileged. If you are not the intended recipient, any disclosure, copying, distribution or action taken is prohibited. SARDI, The South Australian Research and Development Institute, is the research division of Primary Industries and Resources (SA)



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Oct 18 16:16:58 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:40:45 EST