[R] grob questions

Gabor Grothendieck ggrothendieck at gmail.com
Tue Oct 4 22:05:34 CEST 2005


On 10/4/05, Paul Murrell <p.murrell at auckland.ac.nz> wrote:
> Hi
>
>
> Gabor Grothendieck wrote:
> > If I run the following example from:
> > http://www.stat.auckland.ac.nz/~paul/grid/doc/grobs.pdf
> >
> >
> >>grid.newpage()
> >>pushViewport(viewport(w = 0.5, h = 0.5))
> >>myplot <- gTree(name = "myplot", children = gList(rectGrob(name = "box",
> >
> > + gp = gpar(col = "grey")), xaxisGrob(name = "xaxis")))
> >
> >>grid.draw(myplot)
> >>grid.edit("myplot::xaxis", at = 1:10/11)
> >>grid.edit("myplot::xaxis::labels", label = round(1:10/11, 2))
> >>grid.edit("myplot::xaxis::labels", y = unit(-1, "lines"))
> >
> >
> > then
> >
> >
> >>str(myplot$children$xaxis)
> >
> >
> > lists 'at' but not the 'labels'.
> >
> > yet if I do this then the labels are listed:
> >
> >
> >>xx <- xaxisGrob(name = "myX", at = 1:10)
> >>childNames(xx)
> >
> > [1] "major"  "ticks"  "labels"
> >
> >
> > 1. How do I get to labels in the first case?
>
>
> First, if the xaxisGrob has at=NULL then it calculates its tick-marks at
> drawing time (based on the viewport it gets drawn in).  So it does not
> store any labels (it doesn't know what they are until it gets drawn). If
> you specify a non-NULL 'at' then the axis creates labels.
>
> Second, grid grobs are standard R objects (copy-on-modify) so the object
> 'myplot' is not the same object that is being modified by the calls to
> grid.edit().  grid.edit() destructively modifies a copy of the grob that
> grid has stored on its display list;  you refer to the appropriate grob
> via its name (not via an R object).  By comparison, editGrob() takes a
> grob and returns a modified copy of the grob, for example ...

Just one clarification.  What is the scope of names?
In a recent post

  https://www.stat.math.ethz.ch/pipermail/r-help/2005-October/078653.html
  https://www.stat.math.ethz.ch/pipermail/r-help/2005-October/078656.html

it seems that one had to use absolute paths and that seems to be the
case here too where as mkondrin pointed out earlier in this thread

  https://www.stat.math.ethz.ch/pipermail/r-help/2005-October/078635.html

that get.grid("myplot::xaxis::labels")$label works.

Its not clear to me whether names:

- must be in absolute paths
- can be relative to some position under some conditions
- are global across all grob names in use and can be referred to directly
as long as they are unique among all grobs defined so far.

It seems absolute path names work but I am not sure whether the
other possibilities can work under some conditions too.

Also what the scope of viewports?   Absolute path? Relative path?
Global names?  Does it work the same way?  I think at least
absolute and relative paths are avalable here but could you confirm
my understanding and whether the situation is the same for
viewports and grobs?

(In the Windows, and analogously in UNIX, file system one can write
\usr\myname or position oneself to \usr using cd and then refer to
myname in a relative way:

cd \usr
dir myname
)

Thanks.




More information about the R-help mailing list