Skip to content
Prev 255855 / 398506 Next

lattice: how to "center" a subtitle?

On Tue, Apr 5, 2011 at 6:12 AM, David Scott <d.scott at auckland.ac.nz> wrote:
[...]
Let's see: ?xyplot says

          'main': Typically a character string or expression describing
              the main title to be placed on top of each page. [...]

So, lattice is fairly explicit, by R standards, in requiring 'main' to
be "character" or "expression". On the other hand, ?title says

     The labels passed to 'title' can be character strings or language
     objects (names, calls or expressions), or [...]

so it additionally accepts "names" and "calls".

Now, we have
alpha == 2
[1] "call"
[1] FALSE
[1] TRUE
expression(foo)
[1] TRUE
expression(alpha == 2)

So I submit that lattice is behaving exactly as suggested by its documentation.

Now you would naturally argue that this is hiding behind
technicalities, and if "call" objects work for plot(), it should work
for lattice as well. But watch this:
[[1]]
 [1]  1  2  3  4  5  6  7  8  9 10

$main
alpha == 2
Error in as.graphicsAnnot(main) : object 'alpha' not found

...which I would say is "unexpected" behaviour, if not a bug.

The moral of the story is that unevaluated calls are dangerous objects
(try this one out for fun:

foo <- bquote(q(.(x)), list(x = "no"))
do.call(plot, list(1:10, main = foo))

), and carrying them around is not a good idea.

Lattice does use the do.call paradigm quite a bit, and I think it
might be quite difficult to fix it up to handle non-expression
language objects (which will still not fix the type of problem shown
above).

-Deepayan