maptools (version 0.2-2)

plotpolys: Plot polygons

Description

A helper function for plotting polygons in a global bounding box. findInterval2 is a modified version of findInterval2 that permits the vector of break points to start at -Inf and/or finish at Inf. leglabs makes character strings from the same break points.

Usage

plotpolys(pl, bb, col = NA, border = par("fg"), add = FALSE, xlim, ylim, ...)
leglabs(vec, under="under", over="over", between="-")
findInterval2(x, vec, rightmost.closed = FALSE, all.inside = TRUE)

Arguments

pl
list of polygons of class polylist
bb
matrix of polygon bounding boxes - columns are LL(x), LL(y), UR(x), UR(y); note that this argument may be omitted if the polygon list object has an "maplim" attribute, or if both xlim and ylim arguments are given
col
colurs to use for filling the polygons
border
the color to draw the border
add
add to existing plot
xlim, ylim
numeric of length 2, giving the x and y coordinates ranges
...
other arguments passed to polygon
vec
vector of break values
under
character value for under
over
character value for over
between
character value for between
x
numeric vector to be broken into class intervals
rightmost.closed
as in findInterval()
all.inside
as in findInterval()

See Also

Map2poly, findInterval

Examples

Run this code
try2 <- read.shape(system.file("shapes/columbus.shp", package="maptools")[1])
mappolys <- Map2poly(try2, as.character(try2$att.data$NEIGNO))
brks <- round(quantile(try2$att.data$CRIME, probs=seq(0,1,0.2)), digits=2)
colours <- c("salmon1", "salmon2", "red3", "brown", "black")
plotpolys(mappolys, col=colours[findInterval2(try2$att.data$CRIME, brks)])
legend(x=c(5.8, 7.1), y=c(13, 14.5), legend=leglabs(brks),
  fill=colours, bty="n")
title(main=paste("Columbus OH: residential burglaries and vehicle
thefts",
  "per thousand households, 1980"))
try3 <- read.shape(system.file("shapes/sids.shp", package="maptools")[1])
mappolys <- Map2poly(try3, as.character(try3$att.data$FIPSNO))
cols <- c("white", "orange", "red")
np <- integer(length(mappolys))
for (i in 1:length(mappolys)) np[i] <- attr(mappolys[[i]], "nPart")
plotpolys(mappolys, col=cols[np])
title(main="White: one part, orange: two part, red: three part polygons")

Run the code above in your browser using DataCamp Workspace