require(sp)
grd <- GridTopology(cellcentre.offset=c(0.5,0.5),
cellsize=c(1,1), cells.dim=c(10,10))
grd.sp <- as.SpatialPolygons.GridTopology(grd)
data(segdata)
parval <- par()
par(mfrow = c(2, 4), mar = c(0, 1, 0, 1))
d <- numeric()
p <- numeric()
for (i in 1:8) {
idx <- 2 * i
d <- append(d, seg(segdata[,(idx-1):idx]))
p <- append(p, whiteseg(grd.sp, data = segdata[,(idx-1):idx]))
full <- segdata[,(idx-1)] == 100
half <- segdata[,(idx-1)] == 50
plot(grd.sp)
plot(grd.sp[full,], col = "Black", add = TRUE)
if (any(half))
plot(grd.sp[half,], col = "Grey", add = TRUE)
text(5, 11.5, labels =
paste("D = ", round(d[i], 2), ", P = ", round(p[i], 2), sep = ""))
}
par(mfrow = parval$mfrow, mar = parval$mar)
Run the code above in your browser using DataLab