Tony,
This may be of some help. I hope it is sufficiently self explanatory. I
will be out of contact for a week so if you have any queries to response may
be a little slow.
****************************************************************************
********
function(xx, yy, nodes = locator(type = "l"))
{
##counts the number of lines in a polygon which cross a perpendicular
dropped below
##each point in xx,yy
## first strip points beyond max range of polygon nodes
lenxmin <- length(nodes$x)
wch <- c(lenxmin, 1)
points(nodes$x[wch], nodes$y[wch], type = "l", lty = 1)
xnr <- range(nodes$x)
ynr <- range(nodes$y)
indx <- seq(along = xx)
## identify points within largest rectangle defined by nodes first
isin <- xx > xnr[1] & xx < xnr[2] & yy > ynr[1]
& yy < ynr[2]
xx <- xx[isin]
yy <- yy[isin]
indx <- indx[isin]
if(length(xx)) {
##put lines in form of slope and intercept coefficients
xmin <- nodes$x
ymin <- nodes$y
xmax <- c(xmin[-1], xmin[1])
ymax <- c(ymin[-1], ymin[1])
dx <- xmin - xmax
slope <- (ymin - ymax)/dx
intercept <- (ymax * xmin - xmax * ymin)/dx
lenrec <- length(xx)
xmin <- matrix(xmin, ncol = lenxmin, nrow = lenrec, byrow T)
xmax <- matrix(xmax, ncol = lenxmin, nrow = lenrec, byrow T)
xint <- matrix(xx, ncol = lenxmin, nrow = lenrec, byrow = F)
yint <- matrix(yy, ncol = lenxmin, nrow = lenrec, byrow = F)
hint <- t(t(xint) * slope + intercept)
yint <- hint <= yint & ((xint >= xmin & xint
<= xmax) |
(xint <=
xmin & xint >= xmax))
isin[indx] <- is.odd(marsum(ifelse(yint, 1, 0)))
}
points(c(nodes$x, nodes$x[1]), c(nodes$y, nodes$y[1]), type =
"l",
col
= 16, lty = 1)
isin
}
****************************************************************************
*****************
Simon Gatehouse
CSIRO Exploration and Mining,
Newbigin Close off Julius Ave
North Ryde, NSW
Mail: PO Box 136, North Ryde
NSW 1670, Australia
Phone: 61 (2) 9490 8677
Fax: 61 (2) 9490 8921
Mobile: 61 0407 130 635
E-mail: simon.gatehouse at csiro.au
Web Page: http://www.csiro.au/
-----Original Message-----
From: Tony Long [mailto:tdlong at uci.edu]
Sent: Saturday, January 26, 2002 7:13 AM
To: r-help at stat.math.ethz.ch
Subject: [R] selecting clusters of points
All:
Are there any functions out there for selecting all the
points in a region of a plot. I envision something like the
identify() function except one could circle a cloud of points (and
perhaps a vector would be returned of the same length as the points
plotted indicating logical membership in the circled cloud). Perhaps
someone has done something with the locator() function that would
allow this (or can suggest a way I could do this). Thanks. Tony
--
Tony Long
Ecology and Evolutionary Biology
Steinhaus Hall
University of California at Irvine
Irvine, CA
92697-2525
Tel: (949) 824-2562 (office)
Tel: (949) 824-5994 (lab)
Fax: (949) 824-2181
email: tdlong at uci.edu
http://hjmuller.bio.uci.edu/~labhome/
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._