From paul@stat.auckland.ac.nz  Tue May 29 00:50:31 2001
From: paul@stat.auckland.ac.nz (Paul Murrell)
Date: Tue, 29 May 2001 11:50:31 +1200
Subject: [Rd] xyplot,grid.text segfault (PR#948)
References: <200105261124.NAA27403@pubhealth.ku.dk> <x2k834eycd.fsf@blueberry.kubism.ku.dk>
Message-ID: <019001c0e7d0$fb44fc70$175dd882@stat.auckland.ac.nz>

Hi


> grid.text() seems unhappy with being passed a non-character vector for
> the label argument. I think Paul muttered something to the effect that
> he knew there would be that kind of weaknesses in the code.
>
> The following runs successfully (well, at least it doesn't crash - the
> result looks a bit weird):
>
> library(lattice)
> zz <- data.frame(
>                  y=rnorm(100),x=rnorm(100),z=round(rnorm(100)),
>                  g=as.character(rep(1:2,50)))
> xyplot(y~ x|z,data=zz,groups=g,
>             panel = function(x, y, subscripts, groups)
>             grid.text(x=x, y=y,
>                       label=as.character(groups[subscripts]))
>        )


The results look weird because the x and y locations in grid.text are in
"npc" units by default (that is, they are taken as proportions of the
dimensions of the region they are being drawn in).  This means that values
outside the range 0..1 are drawn outside the limits of the plotting region.
You need to specify "native" units in the call so that the x and y locations
are relative to the scales on the axes of the plotting region.  For example,

    grid.text(x=x, y=y,
                  label=as.character(groups[subscripts]),
                  default.units="native")

This unit stuff is a "feature" of the underlying grid graphics, which is
probably why you did not notice it.  The default panel functions do,
however, provide examples of what needs to be done.  See, for example,
panel.xyplot.

Paul


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


[Rd] xyplot,grid.text segfault (PR#948)
Paul Murrell