Sign up ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.


I have exported an ESRI shapefile (polygon) to KML using R, but the resulting layer shows only the outer extent of the polygon. How can I fill in the area with a color? Any help is greatly appreciated.

The code is as follows:

setwd("G:\\GIS_SJR\\GIS Shapefiles\\Boundaries")
polygon <- readOGR(".", "20km_buffer_albers")
polygonWGS <- spTransform(polygon, CRS("+proj=longlat +ellps=WGS84 +datum=WGS84"))  
writeOGR(polygonWGS, dsn="polygonWGS.kml", layer="polygonWGS", driver="KML")
share|improve this question
"Limited support is available for fills, line color and other styling attributes" check their website –  A.R Jan 15 '13 at 9:17
I have a similar issue. I am studying this web site,, my files are in a raster format. try with KML(RAD.all[[100]], file='1998.kml', col=rev(terrain.colors(255)),alpha = 0.5,colNA=NA, maxpixels=100000, blur=2,overwrite=TRUE ) and plotKML(RAD.all[[100]], colour_scale = rev(c(terrain.colors(255))),alpha = 0.5) plotKML works better for me –  Nahm Aug 22 '14 at 21:22
That web site has soil example too. –  Nahm Aug 22 '14 at 21:29

1 Answer 1

up vote 2 down vote accepted

As said in the comments above, the Global Soil Information Facilities (tutorials) website maintained, amongst others, by some of the plotKML authors and contributors gives you everything you need to produce filled polygon areas. In addition to the absolutely correct solution by @Nahm above, here's a reproducible example for future queries on the topic.

## required packages

## shapefile data
spy <- subset(countriesCoarse, continent == "Africa")

## plotKML
plotKML(spy["MAP_COLOR"], filename = "africa.kml",
        colour_scale = worldgrids_pal[["lgn3"]])


You may find extra information on further plotKML settings including supported color palettes here.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.