I am using the sp
package in R
to plot sampled points along a river. However, I would like to zoom in to a sampled area of the entire river, and plot this zoomed area on the full length of the river. Using the spplot
function is useful, as I have various variables per point. To "zoom" in, I can simple change the ylim
and xlim
arguments when using the spplot
function.
Using the meuse
dataset as an example
library(sp)
library(lattice)
data(meuse)
coordinates(meuse)=~x+y
FUll.study<-spplot(meuse) #Gives the full study area
ZOOM<-spplot(meuse, xlim=c(170000, 181000), ylim=c(329714,333611)) #Random area to zoom in.
The results look like this:
However the desired result is something like this:
I am trying to find a way to add the ZOOM
to an area on the Full.study
map.I suspect because spplot
is dependent on lattice
it may not be possible. In that case, I would have to create a map for each variable independently, and add the respective zoomed area, probably through par(new=TRUE)
, but this is just a thought. I would still have to figure out how to specify the location and adjust the size of the of zoomed area.
Best Answer
Here is a suggestion using ggplot. I use
ggplotGrob
to combine the full and zoomed map andgrid.arrange
from the gridExtra add-on to combine the maps for different variables. There are many adjustments that can be made, of course.Similarly, ggplot can handle rasters.