[R] Lattice graphics strip labels for shingles

Greg Snow greg.snow at ihc.com
Tue Oct 18 17:19:16 CEST 2005


Does the strip.shingle function in the TeachingDemos package do what you
want?

Greg Snow, Ph.D.
Statistical Data Center, LDS Hospital
Intermountain Health Care
greg.snow at ihc.com
(801) 408-8111

>>> "Kiermeier, Andreas (PIRSA - SARDI)"
<Kiermeier.Andreas at saugov.sa.gov.au> 10/18/05 12:02AM >>>
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 at 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 at 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




More information about the R-help mailing list