Restricting plot to shapefile boundaries in r
I have analysed a dataset of GPS points using density.ppp to generate a sort of heatmap of intensity of the points, as shown below: However, I would like the image to be limited to the borders of the shapefile, similar to below: The first image is called as x <- readShapePoly("dk.shp") xlim<-c(min(912),max(920)) ylim<-c(min(8023),max(8030)) a<-ppp(cases@coords[,1], cases@coords[,2], xlim, ylim, unitname=c("km")) plot(density.ppp(a, 0.1), col=COLORS) plot(x, add=T, border="white") where cases@coords are the GPS coordinates of each point of interest, and x is a shapefile which provides the