- > x <- c(1:9,8:1)
- > y <- c(1,2*(5:3),2,-1,17,9,8,2:9)
- > op <- par(mfcol=c(3,1))
- > for(xpd in c(FALSE,TRUE,NA)) {
- + plot(1:10, main = paste("xpd =", xpd))
- + box("figure", col = "pink", lwd=3)
- + polygon(x,y, xpd=xpd, col="orange", lty=2, lwd=2, border="red")
- + }
- > par(op)
- > plotPath <- function(x, y, col = "grey", rule = "winding") {
- + plot.new()
- + plot.window(range(x, na.rm = TRUE), range(y, na.rm = TRUE))
- + polypath(x, y, col = col, rule = rule)
- + if (!is.na(col))
- + mtext(paste("Rule:", rule), side = 1, line = 0)
- + }
- >
- > plotRules <- function(x, y, title) {
- + plotPath(x, y)
- + plotPath(x, y, rule = "evenodd")
- + mtext(title, side = 3, line = 0)
- + plotPath(x, y, col = NA)
- + }
- >
- > op <- par(mfrow = c(5, 3), mar = c(2, 1, 1, 1))
- >
- > plotRules(c(.1, .1, .9, .9, NA, .2, .2, .8, .8),
- + c(.1, .9, .9, .1, NA, .2, .8, .8, .2),
- + "Nested rectangles, both clockwise")
- > plotRules(c(.1, .1, .9, .9, NA, .2, .8, .8, .2),
- + c(.1, .9, .9, .1, NA, .2, .2, .8, .8),
- + "Nested rectangles, outer clockwise, inner anti-clockwise")
- > plotRules(c(.1, .1, .4, .4, NA, .6, .9, .9, .6),
- + c(.1, .4, .4, .1, NA, .6, .6, .9, .9),
- + "Disjoint rectangles")
- > plotRules(c(.1, .1, .6, .6, NA, .4, .4, .9, .9),
- + c(.1, .6, .6, .1, NA, .4, .9, .9, .4),
- + "Overlapping rectangles, both clockwise")
- > plotRules(c(.1, .1, .6, .6, NA, .4, .9, .9, .4),
- + c(.1, .6, .6, .1, NA, .4, .4, .9, .9),
- + "Overlapping rectangles, one clockwise, other anti-clockwise")
- >
- > par(op)
- > require(grDevices)
- > ## set up the plot region:
- > op <- par(bg = "thistle")
- > plot(c(100, 250), c(300, 450), type = "n", xlab="", ylab="",
- + main = "2 x 11 rectangles; 'rect(100+i,300+i, 150+i,380+i)'")
- > i <- 4*(0:10)
- > ## draw rectangles with bottom left (100, 300)+i
- > ## and top right (150, 380)+i
- > rect(100+i, 300+i, 150+i, 380+i, col=rainbow(11, start=.7,end=.1))
- > rect(240-i, 320+i, 250-i, 410+i, col=heat.colors(11), lwd=i/5)
- > ## Background alternating ( transparent / "bg" ) :
- > j <- 10*(0:5)
- > rect(125+j, 360+j, 141+j, 405+j/2, col = c(NA,0),
- + border = "gold", lwd = 2)
- > rect(125+j, 296+j/2, 141+j, 331+j/5, col = c(NA,"midnightblue"))
- > mtext("+ 2 x 6 rect(*, col = c(NA,0)) and col = c(NA,\"m..blue\"))")