[R] Expressions in lattice conditional variables
Frank Harrell
f.harrell at vanderbilt.edu
Sat Mar 2 18:18:29 CET 2013
I would like to have a lattice conditioning ( | var ) variable have
expression() as values because I want panel labels to be able to use
plotmath notation for subscripts, etc. lattice barks at this. Does anyone
know of a trick workaround? An attempted example program is below. Thanks
-Frank
require(lattice)
set.seed(1)
var <- c(rep('A', 100), rep('B', 100))
trt <- sample(c('T1','T2'), 200, TRUE)
x <- c(runif(100), 10*runif(100))
y <- x + c(runif(100)/10, runif(100))
N <- tapply(x, llist(var, trt), function(x) sum(!is.na(x)))
print(N)
vn <- vector('expression', length(var))
for(v in unique(var)) {
i <- var == v
n <- tapply(!is.na(x[i]), trt[i], sum)
nam <- names(n)
w <- sprintf('paste(%s," (", n[%s]==%g,~~n[%s]==%g,")")',
v, nam[1], n[1], nam[2], n[2])
cat(w, '\n')
vn[var == v] <- parse(text=w)
n <- sprintf('%s (n%s=%g, n%s=%g)', v, nam[1],n[1], nam[2],n[2])
vn[var == v] <- n
}
trt <- factor(trt)
xyplot(as.integer(trt) ~ x | vn, panel=panel.bpplot, ylim=c(0,3),
scale=list(y=list(at=1:2, labels=levels(trt)),
x=list(relation='free', limits=list(c(0,1),c(0,13)))),
ylab='Treatment', layout=c(1,2))
Error in unique.default(x) :
unimplemented type 'expression' in 'HashTableSetup'
-----
Frank Harrell
Department of Biostatistics, Vanderbilt University
--
View this message in context: http://r.789695.n4.nabble.com/Expressions-in-lattice-conditional-variables-tp4660089.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list