[R] How to overlay a vector map (polygon) on raster maps?

Kristi Glover kr|@t|@g|over @end|ng |rom hotm@||@com
Thu Apr 11 13:28:31 CEST 2019


He R users,
I have been struggling to plot a boundary map over the raster maps. I tried using the following example, but the boundary map could not be displayed over the three raster maps.
It works if we plot for a single raster. However when I want to plot the three maps using "levelplot" and add the boundary map it did not work.  I wanted to plot three raster same time because the "levelplot" so that we can compare the maps as they have only one legend.

My example code is given below, do you have any suggestions?


library(gridExtra)

library(raster)

library(sp)

library(rasterVis)

library(rgdal)

library(maptools)


boundary<- readShapeSpatial("boundrymap.shp")


minTemp<-raster("minTemp.tif")

maxTemp<-raster("maxTemp.tif")

averageTemp<-raster("averageTemp.tif")

Temp<-stack(minTemp,maxTemp,averageTemp)


levelplot(Temp, layout=c(1,3))+ layer(sp.polygons(boundary, col = "yellow"))

thanks


	[[alternative HTML version deleted]]



More information about the R-help mailing list