[R] Inverting polygon

white.denis@epamail.epa.gov white.denis at epamail.epa.gov
Mon Sep 30 00:25:53 CEST 2002


> Hi
>
> I'm using polygon to delimit an area on a plot. However my
> intention is to "superpose" the outside area of the polygon
> (I want to cover an extrapolation of contour(interp(...)).
>
> Is there an easy way of doing it ?
>
> Thanks
>
> EJ

Below is one way that may work.  The last call to lines is (a kludge) to
cover up the "retraced line" from the outer part of the polygon defined
by the range of the plot data to the inner part of the polygon defined
by your polygon of interest.

n <- 50 * 3
x <- runif (n)
y <- runif (n)
x[(seq(n) %% 3) == 0] <- NA
y[(seq(n) %% 3) == 0] <- NA

plot.new ()
range.x <- range (x, na.rm=TRUE)
range.y <- range (y, na.rm=TRUE)
plot.window (range.x, range.y, asp=1)
lines (x, y)

wind.x <- c(range.x, rev (range.x), range.x[1])
wind.y <- c(range.y[1], range.y, rev (range.y))
polygon (wind.x, wind.y)

poly.x <- wind.x / 2 + 0.25
poly.y <- wind.y / 2 + 0.25
polygon (poly.x, poly.y)

mask.x <- c(wind.x, poly.x)
mask.y <- c(wind.y, poly.y)
polygon (mask.x, mask.y, col="white")

lines (c(wind.x[1], poly.x[1]),
       c(wind.y[1], poly.y[1]), col="white")

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list