Skip to content
Prev 101634 / 398500 Next

panel-dependent distribution in qqmath

On 10/11/06, Benjamin Tyner <btyner at gmail.com> wrote:
You have the right idea, but prepanel is called in a context (when the
object is being created) that is fundamentally different from when
panel is called (when the object is being plotted). In particular,
panel.number() makes no sense in the first context. packet.number()
does, but implementation will be non-trivial. Since I don't expect
this to be a very common use, I'm not going to even try, but you can
fake it by using the hack that originally gave rise to the
'panel.number' concept, namely, keep an external counter. One solution
which does not pollute the search path is:

lattice.options(counter = 1)

qqmath(~ val | ind,
       layout=c(3,1),
       data = mydata,
       prepanel = function(x, distribution, ...) {
           counter <- lattice.getOption("counter")
           mydist <- function(p) qt(p, df = counter + 1)
           lattice.options(counter = counter + 1)
           prepanel.qqmathline(x, distribution=mydist,...)
       },
       panel = function(x, distribution, ...) {
           mydist <- function(p) qt(p, df = panel.number() + 1)
           panel.qqmathline(x, distribution=mydist,...)
           panel.qqmath(x, distribution=mydist,...)
       })

-Deepayan