# [Rd] grobX for points?

Felix Andrews felix at nfrac.org
Mon Jul 28 07:16:00 CEST 2008

```On Mon, Jul 28, 2008 at 7:41 AM, Paul Murrell <p.murrell at auckland.ac.nz> wrote:
> Hi
>
>
> 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
> degrees).
>
> 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 (?)

I am doing the latter, which is easy enough. Can I suggest that
grobX.Rd be updated to mention that it returns the convex hull for
points, lines and segments (?) objects? It currently reads

"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 exception to this is a polygon grob describing multiple
polygons; in that case, the edge corresponds to a convex hull around
all points of all polygons described by the grob."

Regards,
Felix

>
> Paul
>
>
>>> 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
> Auckland
> New Zealand
> 64 9 3737599 x85392
> paul at stat.auckland.ac.nz
> http://www.stat.auckland.ac.nz/~paul/
>

--
Felix Andrews / 安福立
PhD candidate
Integrated Catchment Assessment and Management Centre
The Fenner School of Environment and Society
The Australian National University (Building 48A), ACT 0200
Beijing Bag, Locked Bag 40, Kingston ACT 2604
http://www.neurofractal.org/felix/
3358 543D AAC6 22C2 D336 80D9 360B 72DD 3E4C F5D8

```