Hi all,

I am having a (known) problem with plotting polygons with islands and holes. I would like to visually mask my raster data with a polygon overlay. The problem is that my polygon data has islands/holes, and these are not drawn correctly when used as an overlay with the spplot panel function.

When I use spplot directly to plot my polygons there is no problem:
spplot(countryOverlay [which(countryOverlay $FID_Countr==0),],"CNTRYNAME", ylim=c(300000,624000), xlim=c(0,285000),col.regions=c("transparent","transparent","transparent","blue","transparent") )
(see spplot.png)

Now I would like to use the spplot panel function to draw the same data as an overlay: spplot(countryOverlay,"CNTRYNAME" ,ylim=c(300000,624000), xlim=c(0,285000) , panel = function(...) { sp.polygons( countryOverlay [which(countryOverlay $FID_Countr==0),], fill = "blue",col = "black")
   }
)
But now, the islands are gone! (see sp.polygons.png)
(The example above is just to demonstrate this problem/feature, it does not draw my gridded data.)

Is it possible to draw the polygons as an overlay, and preserve the islands? Maybe use another function? I see that sp.polygon uses grid::polygonGrob, and is documented that this function does not preserve the holes. I find it strange that spplot itself can draw the dataset correctly, so it must be possible to draw the polygon correctly as an overlay... or not?

If people are interested, I have a small R script available with some test data to demonstrate the problem.

Best Regards,
Maarten Plieger

--
Maarten Plieger
KNMI, R&D Information and Observation Technology, De Bilt
(t) +31 30 2206330

<<inline: sp.polygons.png>>

<<inline: spplot.png>>

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to