Skip to content
Prev 82977 / 398503 Next

How to draw partial grid in plot for spatial-binomial experiment?

On Mon, 19 Dec 2005, Marc Schwartz (via MN) wrote:

            
An alternative is to use functions in the sp package:

library(sp)
fri2 <- SpatialPoints(fri$coords)
fri2_SP <- SpatialPixels(fri2)
fri2_SPl <- as.SpatialPolygons.SpatialPixels(fri2_SP)
fri2_SPl_df <- SpatialPolygonsDataFrame(fri2_SPl, 
  data.frame(data=fri$data, units.m=fri$units.m, 
  row.names=IDvaluesSpatialPixels(fri2_SP)))
opar <- par(mfrow=c(1,2))
plot(fri2_SPl_df, axes=TRUE)
text(coordinates(fri2_SPl_df), label=format(fri2_SPl_df$data), cex=0.6)
title(xlab="Easting (km)", ylab="Northing (km)", main="Success")
plot(fri2_SPl_df, axes=TRUE)
text(coordinates(fri2_SPl_df), label=format(fri2_SPl_df$units.m), cex=0.6)
title(xlab="Easting (km)", ylab="Northing (km)", main="Trials")
par(opar)

which captures most of the polygon drawing for you. It has to go from 
points to pixels to polygons to induce the regular shapes.

Roger