I was trying to use overlay function and the code is the following:
usa <- map('state',boundary = FALSE, lty=2,plot=FALSE,fill=TRUE)
usa_SP <- map2SpatialPolygons(usa, IDs=usa$names, proj4string = CRS("+proj=longlat"))
comB.dat <- read.csv("agbregion.csv",header=TRUE)
names(comB.dat) <- c("Lon","Lat","harvDB")
names(AGByr)<- c("Lon","Lat","harvDB")
names(AGBdiff) <- c("Lon","Lat","harvDB")
pts <- SpatialPoints(cbind(comB.dat$Lon,comB.dat$Lat))
ptsyr <- SpatialPoints(cbind(AGByr$Lon,AGByr$Lat))
ptsdiff <- SpatialPoints(cbind(AGBdiff$Lon,AGBdiff$Lat))
o <- overlay(pts, usa_SP)
But I got the following error: Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘overlay’ for signature ‘"SpatialPoints", "SpatialPolygons"’
I don't know what's going on. Could anybody explain it for me? Thanks a lot.