[R] grid: clipping points to viewport?

Paul Murrell p.murrell at auckland.ac.nz
Mon Feb 17 21:28:18 CET 2003


M.Kondrin wrote:

> Why command 
> grid.points(c(0,1,1.1),c(0,1,1.1),vp=viewport(w=0.5,h=0.5,x=0.5,y=0.5,clip=TRUE)) 
> does not clip points (point (1.1,1.1) is still visible), although there 
> is no problem with grid.lines(...)?

What version/device is this happening on?
This works for me (R 1.6.2, X11/postscript)

> And one more question - how can I swap direction of tick marks on 
> grid.x(y)axis to turn it inside plot?

If I understand what you mean, there is no argument to grid.x(y)axis 
that will do what you want.  This is something that should probably be 
added at some piont.  For now, it is pretty straightforward to do 
something by hand.  The following may help ...

x <- rnorm(10)
y <- rnorm(10)
push.viewport(dataViewport(x, y))
grid.points(x, y)
tick.loc <- grid.pretty(range(x))
grid.segments(unit(tick.loc, "native"),
               unit(tick.loc, "native"),
               unit(0.5, "lines"))
grid.lines(unit(range(tick.loc), "native"), 0)
grid.text(tick.loc, unit(tick.loc, "native"),
           unit(-0.5, "lines"))

Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
New Zealand
64 9 3737599 x85392
paul at stat.auckland.ac.nz

More information about the R-help mailing list