[R] grid package and lines

Paul Murrell p.murrell at auckland.ac.nz
Wed Nov 27 20:59:06 CET 2002


Hi


"Willemsen, Sten" wrote:
> 
> Hello list,
> 
> When using the grid package in R 1.60 under windows grid.lines and
> grid.line.to seem not to use the coordinate system as defined by the current
> viewport whereas grin.points does. Am I doing something wrong?


I think you are getting bitten by the fact that the locations for
drawing points and lines can be specified in a number of different
coordinate systems.  There is a default coordinate system for each
graphical primitive;  for points the default is "native" which means
that points are drawn relative to the x-scale and y-scale of the current
viewport, but for lines the default is "npc" which means that lines are
drawn relative to a "normalised" coordinate system [bottom-left corner
of the viewport is (0,0), top-right corner is (1,1)].  The defaults are
there so that you can ignore the use of "units" to specify a coordinate
system in some cases, but if the default isn't what you want then you
will have to get your hands dirty :)  [Complaints about selection of
inappropriate default units should be directed to me :(]

I hope the following example (comments included) helps to show what is
going on ...

    library(grid)
    x <- rnorm(10)
    y <- rnorm(10)
    push.viewport(plotViewport(c(5, 5, 3, 2)))
    push.viewport(dataViewport(x, y))
    grid.rect(gp=gpar(lty="dashed"))
    grid.xaxis()
    grid.yaxis()
    # default units for grid.points are "native"
    grid.points(x, y)
    # can specify other units
    grid.points(c(0, 0, 1, 1),
                c(0, 1, 1, 0),
                default.units="npc",
                pch=16)
    # default units for grid.lines are "npc"
    grid.lines(c(0, 0.5, 1, 0.5, 0),
               c(0.5, 1, 0.5, 0, 0.5),
               gp=gpar(col="green"))
    # can specify other units
    grid.lines(unit(x, "native"),
               unit(y, "native"))
    

Paul
-- 
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x5392
paul at stat.auckland.ac.nz
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list