[R] Custom strips in lattice
Jim Price
price_ja at hotmail.com
Wed Jun 18 18:28:36 CEST 2008
I've recently been playing with strip functions for a data presentation I'd
like to use, and have a couple questions. I've cannibalised the
useOuterStrips function from latticeExtra to give me the following sample
code:
library(lattice)
myData <- expand.grid(
type = c('First 3 days','Whole profile'),
sub = paste('Subject', 1:3, '\nDescription'),
time = 1:10
)
myData$resp <- rnorm(nrow(myData))
y.limits <- rep(with(myData, by(resp, sub, function(.x)
range(pretty(range(.x))))), each = 2)
xyplot(
resp ~ time | type * sub,
data = myData,
strip.left = function(which.given, which.panel, var.name, par.strip.text,
...)
if(which.given == 1)
strip.default(which.given = 1, which.panel = which.panel[1], var.name =
var.name[1], par.strip.text = list(cex = 0.75), ...),
strip = function(which.given, which.panel, var.name, par.strip.text, ...)
if(which.given == 2)
strip.default(which.given = 1, which.panel = which.panel[2], var.name =
var.name[2], par.strip.text = list(cex = 0.75), ...),
as.table = T,
scales = list(
x = list(relation = 'free', limits = list(c(1,3), c(1,10))),
y = list(relation = 'free', limits = y.limits)
)
)
There are 2 changes I'd like to make:
Firstly, I'd like to expand the top strip only, so I can add more (than 2)
rows of text. Normally I'd do that through calling par.strip.text with the
lines argument. However, this appears to effect both strips. As above, I
could define a par.strip.text inside each custom function, but this doesn't
appear to work; indeed, the default for strip.default,
trellis.par.get('add.text'), doesn't include this as an option, so I assume
that there is some preprocessing that goes on (in the prepanel function?).
Secondly, although I have custom y-axis ranges, you can see from the graph
that the rows represent the same subject; hence, in the interest of saving
space, I'd prefer to have no gap between columns. This isn't a show stopper
though, so if it's not possible it's no great loss.
I've looked through Deepayan's book (and, as many have done previously,
extend my thanks as, despite being a fairly frequent lattice user, I've
learnt a great deal from it - although I've not finished it yet, so if the
answers are in there somewhere my apologies!) and couldn't see these issues
addressed. If anyone has a solution it would be much appreciated.
Thanks!
Jim Price
Cardiome Pharma Corp.
sessionInfo()
R version 2.7.0 (2008-04-22)
i386-pc-mingw32
locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
States.1252;LC_MONETARY=English_United
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] latticeExtra_0.4-1 RColorBrewer_1.0-2 lattice_0.17-6
loaded via a namespace (and not attached):
[1] grid_2.7.0
--
View this message in context: http://www.nabble.com/Custom-strips-in-lattice-tp17986269p17986269.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list