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 outline for the geographical unit.
The second image is called using this code:
plot(x, axes=T, col=COLORS, border="White")
Does anyone know how this might be done? Perhaps it's not possible with plot() and I will need another package.
As an aside, the next step I plan to do will be to overlay this image over a map imported from GoogleEarth. I'm not yet sure how to do that either, but will post the answer if and when I work it out
many thanks
plot()
uses thexlim
andylim
you provided above. If you want to manually adjust them useplot(...,ylim=c(0,100),xlim=c(0,100)
You will find the xlim and ylim values from the shapefile callingx@bbox
– jakob-rpolygon
, defining your polygon between the shape borders and the plot borders, and filling that area with white or other background color. But I bet someggplot
ormaptools
expert will chime in with the correct answer :-) – Carl Witthoft