[Rd] grobX for points?

Paul Murrell p.murrell at auckland.ac.nz
Sun Jul 27 23:41:12 CEST 2008


Felix Andrews wrote:
> Hi R-devel,
> It seems that grobX and grobY (from the grid package) do not refer to
> the bounding box of a grid.points object.
> library(grid)
> library(lattice)
> xyplot(1:10 ~ 1:10)
> downViewport("plot1.panel.1.1.vp")
> grob <- grid.get("GRID.points", grep=TRUE)
> convertX(grobWidth(grob), "cm")
> # 10.3430190058480cm
> # (correct, but:)
> convertX(grobX(grob, "west"), "cm")
> # 5.89552083333333cm
> convertX(grobX(grob, "east"), "cm")
> # 5.89552083333334cm
> So grobX is returning the midpoint, rather than the bounding box. This
> is surprising, given that ?grobX says "If the grob describes multiple
> shapes, in most cases, the boundary value will correspond to the edge
> of a bounding box around all of the shapes."

The grobX() and grobY() calculations for "points" grobs is "imperfect"
because it treats the grob as a set of point locations and does NOT take
into account the size and shape of the actual data symbols.  This means
that a points grob is not treated as multiple shapes, but in fact as a
single set of points.  Hence, the calculations of the boundary for the
shape generate a convex hull around the point locations.  In this case,
the points all lie along a straight line, so the convex hull is a long
thin "cigar" at a 45 degree angle.  The calculation of points on this
boundary draws a line from the centre of the convex hull to the edge.
In this case, the line will intersect the convex hull boundary at the
centre of the set of points for all angles (apart from possibly 45

If you want to work with the bounding box for the points, perhaps you
could draw an invisible rectangle based on the range of the data and
work off that, or just use convertX() on the range of the data (?)


>> sessionInfo()
> R version 2.7.1 (2008-06-23)
> i386-pc-mingw32
> locale:
> LC_COLLATE=English_Australia.1252;LC_CTYPE=English_Australia.1252;LC_MONETARY=English_Australia.1252;LC_NUMERIC=C;LC_TIME=English_Australia.1252
> attached base packages:
> [1] grid      stats     graphics  grDevices utils     datasets
> methods   base
> other attached packages:
> [1] playwith_0.9-10      cairoDevice_2.8      gWidgetsRGtk2_0.0-36
> RGtk2_2.12.5-3       gWidgets_0.0-28
> [6] lattice_0.17-10
> loaded via a namespace (and not attached):
> [1] gridBase_0.4-3 tools_2.7.1

Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
New Zealand
64 9 3737599 x85392
paul at stat.auckland.ac.nz

More information about the R-devel mailing list