[R] fill the area outside a polygon

Adrian Dușa dusa.adrian at unibuc.ro
Wed Dec 2 13:07:14 CET 2015

Dear All,

I know how to fill a polygon, using a basic R graphics device:

par(mai=c(0, 0, 0, 0))
plot(1:100, type="n")
polygon(c(20, 80, 80, 20), c(20, 20, 80, 80), col="lightblue")

But let's say I have an outer polygon like this:
polygon(c(0,100,100,0), c(0,0,100,100))

Is it possible to fill the area between the two polygons?

I realise there is a quick and dirty solution to fill the outer polygon,
then draw the inner polygon colored with white, but I would like to
actually "clip" the outer polygon to the boundaries of the inner one.

Of course, there are various packages which draw maps (i.e. maptools), but
I need this in base R graphics. In other words, is it possible to define a
polygon with a hole inside, in base R?

Thank you,

Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5

	[[alternative HTML version deleted]]

More information about the R-help mailing list