[R] Using hexbin to Eliminate Indiscernible Points from a Plot
Steve Dutky
sdutky at terpalum.umd.edu
Sun Dec 19 17:48:38 CET 2004
Dear all,
I have installed hexbin 1.1-4 package and cobbled together
the following function, cull, to eliminate xy points closer
than a specified resolution. While it appears to reduce the
congestion of points on a plot, I am surprised to see
overlapping points remain.
I would appreciate any insight as to what may cause this and
as to whether a better way to reduce plot congestion may exist.
Thanks, Steve Dutky
sdutky at terpalum.umd.edu
+1-301-545-4113
"cull"<-function(x,y,PAR=par(),resolution=PAR$cin[1]/2) {
#
# returns a logical vector of points that are discernible at
# the specified resolution.
# requires that either that PAR argument be passed explicity
# as named list of "cin" and "pin" parameters or that active
# graphics device already sized for plotting x and y
# PARS$pin == width X height of plot areas in inches
bins<-ceiling(PAR$pin/resolution)[1]
shape<-PAR$pin[2]/PAR$pin[1]
if (missing(y)) #assume x has two columns
!duplicated(hexbin(x[,1],x[,2],xbins=bins,shape=shape,IDs=T)@cID)
else
!duplicated(hexbin(x,y,xbins=bins,shape=shape,IDs=T)@cID)
}
#example:
library(hexbin)
m<-cbind(rnorm(10000),rnorm(10000))
plot(apply(m,2,FUN=range))
k<-cull(m, resolution=9/72)
plot(m[k,])
More information about the R-help
mailing list