Re: [R] plot the number of replicates at the same point

From: Jim Lemon <bitwrit_at_ozemail.com.au>
Date: Fri 15 Jul 2005 - 18:49:15 EST


Hi all,

This is nowhere near as elegant as Deepayan's solution, but I read the spec as plotting symbols except where there were overlays. You are welcome to improve the following...

Jim

count.overplot<-function(x,y,tol=NULL,...) {  if(missing(x))
  stop("Usage: count.overplot(x,y,tol=NULL,...)")  dimx<-dim(x)
 # if x is a data frame or matrix with at least two columns, split it  if(missing(y) && !is.null(dimx)) {
  y<-x[,2]
  x<-x[,1]
}

 xlen<-length(x)
 if(xlen != length(y)) stop("x and y must be the same length.")  if(is.null(tol)) tol<-c((max(x)-min(x))/1000,(max(y)-min(y))/1000)  flags<-1:xlen
 xsep<-ysep<-xdup<-ydup<-xydup<-rep(0,xlen)  nsep<-ndup<-0
 for(i in 1:xlen) {
  if(!is.na(flags[i])) {
   dups<-abs(x - x[i]) <= tol[1] & abs(y - y[i]) <= tol[2]    ndups<-sum(dups)
   if(ndups > 1) {
    ndup<-ndup+1
    xydup<-ndups
    xdup[ndup]<-x[i]
    ydup[ndup]<-y[i]
   }
   else {
    nsep<-nsep+1
    xsep[nsep]<-x[i]
    ysep[nsep]<-y[i]
   }
  }
  flags[dups]<-NA
}

 plot(xsep[1:nsep],ysep[1:nsep],...)
 text(xdup[1:ndup],ydup[1:ndup],xydup[1:ndup]) }



R-help@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 Received on Fri Jul 15 08:46:08 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:33:43 EST