Hi, I am trying to show grid cells with colors. Colors depends on the number of points falling within grid cells. Here is what I did;
rm(list=ls(all=T)) library(sp) library(maptools) library(PBSmapping) ### Define parameters for a grid 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") r.grd.ps <- SpatialPolygons2PolySet(r.grd) ### Plot random points x <- rnorm(10000) y <- rnorm(10000) events <- as.EventData(data.frame(EID = 1:10000, X=x, Y=y)) ### Count # of points within cells n_in_cells <- findPolys(events, r.grd.ps) n_cells <- aggregate(n_in_cells, list(n_in_cells[,2]), sum)[,c(1,4)] Then I would like to add n_cells to r.grd.ps, and show maps with colored cells using plotPolys(). Any suggestions? Thank you very much tk _______________________________________________ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo