[R] grid.edit problem
Paul Murrell
p.murrell at auckland.ac.nz
Sun Oct 16 23:35:16 CEST 2005
Hi
Gabor Grothendieck wrote:
> Thanks, again. I see its basically an origin problem so that, for
> example, this would have worked too:
>
> grid.edit("L", x = grid.get("L")$x + unit(10, "native") - unit(0, "native"))
Right.
And your solution might be easier for people to read and write too :)
> By the way, could unit.c, unit.rep and unit.length
> be named c.unit, rep.unit and length.unit (since
> then they would just be methods of the respective
> S3 generics and no new names would need to be
> introduced or remembered).
Yes, for rep() and length() (I think the original functions were
written when the corresponding base functions were not generic).
c() is a bit harder because of its ... argument. If all of the ...
arguments are units it could work, but the result of c(1, unit(...))
would be a very nasty mess.
Paul
> On 10/16/05, Paul Murrell <p.murrell at auckland.ac.nz> wrote:
>
>>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
>>paul at stat.auckland.ac.nz
>>http://www.stat.auckland.ac.nz/~paul/
>>
>>
>
>
> ______________________________________________
> R-help at 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
--
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/
More information about the R-help
mailing list