Hi
Gabor Grothendieck wrote: > I am having a problem in editing a grob. It works ok if I try to > shift the grob using npc coordinates but if I do the same thing > using native coordinates the grob disappears. What is wrong? > > > library(grid) > grid.newpage() > > # create viewport > pushViewport(viewport(xscale = c(100,200), name = "X")) > > # draw vertical line > grid.lines(150, 0:1, default.units = "native", name = "L") > > # move line 25% of the way to the right. Works ok. > grid.edit("L", x = grid.get("L")$x + unit(0.25, "npc")) > > > # but now repeat it shifting it using native coordinates > ######################################################## > > # remove line and draw a new line where the original one was > grid.remove("L") > grid.lines(150, 0:1, default.units = "native", name = "L") > > # move line 25% of the way to the right but use native coordiantes > #### line disappears !!!!!!!!! > grid.edit("L", x = grid.get("L")$x + unit(25, "native")) This is due to the fact that the *location* unit(25, "native") is very different from the *location* unit(.25, "npc"). In your example, the former actually corresponds to unit(-.75, "npc"). What you appear to be trying to do is add a *dimension* (width) unit(25, "native"), which corresponds to a *dimension* unit(.25, "npc"), to the original *location* unit(150, "native"). Problem is, the 'x' component of a "line" is interpreted as a location so your unit(25, "native") is interpreted as a location. This issue is described in one of the small grid doc's at http://www.stat.auckland.ac.nz/~paul/grid/doc/locndimn.pdf A (rather verbose) way of specifying your goal is the following ... grid.edit("L", x = grid.get("L")$x + # Convert a width into a location convertUnit(unit(25, "native"), "native", "x", "dimension", "x", "location")) ... or, if you know you are only dealing with "native" (data) values, you could add them together before using them to specify a location ... x <- 150 + 25 grid.edit("L", x = unit(x, "native")) Paul -- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 [EMAIL PROTECTED] http://www.stat.auckland.ac.nz/~paul/ ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html