[R] Varying grid.rect in different panels of a Lattice plot

2005-03-16 Thread Leon Barmuta
Dear r-help,
Sleep-deprivation from having 2 youngsters under 2 around the house is 
fuzzing my brain, so please be gentle if the answer to this query is obvious!

In the example below, I'm trying to use grid.rect to add grey rectangles to 
the panels of a lattice plot to indicate which months spawning occurred of 
a (very cute) native Tasmanian fish. The fish in the two lakes spawned at 
slightly different times, so grid.rect needs to be conditioned on when 
spawning happened in each lake. However, the panel function I wrote first, 
and reproduce below, inserts grey rectangles for all dates that spawning 
occured pooled across the two lakes. So after dreging r-help, I've messed 
with subscripts and tried fiddling with panel.number, but can't get this to 
work. Any suggestions most welcome!

# Make up a short data set
library(lattice)
library(grid)
Lake - rep(c(Crescent,Sorell), each=13)
Spawning - c(Y, rep(N,7), rep(Y,4), rep(N,8), rep(Y,5), N)
Catch - rpois(26, 30) # fake data
Plotdate - rep(seq(as.Date(2000/10/1), by=month, length=13),2)
trellis.device(theme=col.whitebg())
# panel function that doesn't quite work
myPanel - function(x, y, ...) {
 grid.rect(x=unit(Plotdate[Spawning == Y], native),
  just=left, width=unit(31, native), # a bit of a fudge
  gp=gpar(col=transparent, fill=light grey))
  panel.xyplot(x, y, ...)}
xyplot(Catch ~ Plotdate|Lake, type=b,
  panel=myPanel,
  layout=c(1,2), xlab=,
  scales = list(x=list(rot = 45, at=as.numeric(Plotdate),
labels=format(Plotdate, %b%Y
Regards,
Leon
-
Dr Leon A. Barmuta, Senior Lecturer in Zoology
School of Zoology  TAFI, University of Tasmania, Private Bag 5, Hobart, 
Tasmania 7001, Australia
Phone (03) 6226 2785;  Fax (03) 6226 2745; International callers replace 
(03) with +61 3
School of Zoology web page: http://www.scieng.utas.edu.au/zoo/
My web page: http://www.scieng.utas.edu.au/zoo/pagedetails.asp?lpersonId=222

__
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


[R] Skipping panels in Lattice

2004-09-08 Thread Leon Barmuta
Dear all,
I wish to generate a lattice boxplot which skips an empty cell in a design. 
I have trawled r-help, scruitinized xyplot(lattice) help page, and merrily 
reproduced examples of using skip from a couple of previous r-help queries 
and the example given in Pinheiro  Bates. But I must be missing something...

Here's an example (running R 1.9.1 on Win2k):
# generate some data
df1 - data.frame(expand.grid(obsnum=seq(1, 15, 1), faca=c(A1, A2, A3),
facb=c(B1,B2, B3, B4), facc=c(C1,C2)), dv=rpois(15*3*4*2,10))
# now get rid of the cell B4  C1 to simulate a missing treatment combination
df2 - df1[df1$facb !=B4 | df1$facc !=C1, ]
# plain vanilla lattice plot generates an empty panel corresponding to the 
empty cell

plot1 - bwplot( dv ~ faca | facb*facc, data=df2)
plot1
# now try to skip the empty panel
# turn plot history on so that the separate pages can be recalled
plot2 - update(plot1, skip=c(rep(F, 3), T, rep(F, 4)))
plot2
and the 4th panel position of the bottom row is skipped, BUT the B4C1 cell 
is shunted to the top left of row 1 and the last panel of plot1 is now 
moved to page 2. Messing with layout= doesn't help, neither does 
substituting NA for the values of the missing cell (instead of cutting it 
out of the data frame). I also get the same behaviour for stripplot and 
dotplot too.

Apologies if I've missed a previous solution to this during my searches of 
the archive.

Regards,
Leon Barmuta
School of Zoology  TAFI, University of Tasmania, Australia.
__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html