Dear all,

Following a code suggested by Roger Bivand (thanks Roger!), I made a little modification to my own case. 

My questions are: (1) how can I plot only those polygons where I have "cnt">0; (2) how can I define classes of "cnt" (like 1-5; >5 to 20; >20-100) and choose a color for each level of cnt? (3) just suppose that my points have an attribute like species name, how can I generate a new collum like cnt_species with the number of species on each polygon?

Below follow the code wrote by Roger Bivand.

Thanks in advance

Miltinho

===
library(sp)
start.point <- -5
cco <- c(start.point,start.point)
csize <- c(1,1)
n <- abs(cco[1]*2)+1
cnum <- c(n,n)
grd <- GridTopology(cco, csize, cnum)
r.grd <- as(grd, "SpatialPolygons")

set.seed(1)
x <- rnorm(10000)
y <- rnorm(10000)
xy <- SpatialPoints(cbind(x, y))

o1 <- overlay(xy, r.grd)
res <- numeric(prod(cnum))
tres <- table(o1)
ntres <- as.integer(names(tres))
res[ntres] <- tres
IDs <- sapply(slot(r.grd, "polygons"), function(x) slot(x, "ID"))
resdf <- data.frame(cnt=res, row.names=IDs)
r.grd.df <- SpatialPolygonsDataFrame(r.grd, resdf)
spts <- list("sp.points", xy, pch=".", col="black")
spplot(r.grd.df, "cnt", sp.layout=spts)



 para armazenamento!

	[[alternative HTML version deleted]]


