Hi


Deepayan Sarkar wrote:
On Thursday 19 August 2004 06:38, Matthew Walker wrote:

I'm baffled as to how the Lattice package achieves clipping.  Would
someone mind explaining this to me?

Firstly, my attempt using "just" the grid package:

x<-seq(0,3,by=0.3)/2.8
y<-seq(0,1,by=0.1)

grid.newpage()
grid.rect(gp=gpar(fill="pink"))

vp<-viewport(width=0.8, height=0.8)


You need to add 'clip="on"' here. Clipping is a property of viewports (not individual 'grob'-s as produced by grid.points and grid.lines), controlled by the 'clip' argument to viewport(). Details (and caveats) in ?viewport.


If your aim is to draw outside the lattice panel, one way is to write a panel function that pushes a viewport with clipping turned off. The following gratuitous example also shows how you can recreate the x- and y-axis ranges in the new viewport.

library(grid)
data(quakes)
Depth <- equal.count(quakes$depth, number=8, overlap=.1)
# extra lines clipped to panel
xyplot(lat ~ long | Depth, data = quakes,
       panel=function(x, y, ...) {
         panel.xyplot(x, y, ...)
         grid.lines(c(155, 200), c(-40, -10),
                    gp=gpar(lwd=3),
                    default.units="native")
         })
# extra lines extend beyond panel
xyplot(lat ~ long | Depth, data = quakes,
       panel=function(x, y, ...) {
         panel.xyplot(x, y, ...)
         xscale <- convertX(unit(0:1, "npc"), "native", valueOnly=TRUE)
         yscale <- convertY(unit(0:1, "npc"), "native", valueOnly=TRUE)
         pushViewport(viewport(clip="off",
                               xscale=xscale, yscale=yscale))
         grid.lines(c(155, 200), c(-40, -10),
                    gp=gpar(lwd=3),
                    default.units="native")
         popViewport()
         })

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/

______________________________________________
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to