Skip to content
Prev 255803 / 398506 Next

lattice: how to "center" a subtitle?

On 05/04/11 05:58, David Winsemius wrote:
I am not sure where I read it and I can't find it again, but my 
understanding is that expressions using bquote with lattice need to be 
enclosed in as.expression() to work. That is in contrast to what happens 
in base graphics.

Here is a simple example.

a <- 2
plot(1:10, a*(1:10), main = bquote(alpha == .(a)))
require(lattice)
xyplot(a*(1:10)~ 1:10, main = bquote(alpha == .(a)))
xyplot(a*(1:10)~ 1:10, main = as.expression(bquote(alpha == .(a))))

Which produces:

 > a <- 2
 > plot(1:10, a*(1:10), main = bquote(alpha == .(a)))
 > require(lattice)
Loading required package: lattice
 > xyplot(a*(1:10)~ 1:10, main = bquote(alpha == .(a)))
Error in trellis.skeleton(formula = a * (1:10) ~ 1:10, cond = list(c(1L,  :
   object 'alpha' not found
 > xyplot(a*(1:10)~ 1:10, main = as.expression(bquote(alpha == .(a))))

Using expression() rather than as.expression() doesn't produce the 
desired affect. Try it yourself.

As to why this is the case .....

David Scott