Skip to content

Instantly share code, notes, and snippets.

@oscarperpinan
Created August 30, 2016 07:24
Show Gist options
  • Save oscarperpinan/c01c4748f38d38782cb221595451b3d2 to your computer and use it in GitHub Desktop.
Save oscarperpinan/c01c4748f38d38782cb221595451b3d2 to your computer and use it in GitHub Desktop.
Inset graphics with rasterVis and grid
library(raster)
library(rasterVis)
library(grid)
r <- raster(system.file("external/test.grd", package="raster"))
## Main graphic
p1 <- levelplot(r)
## Inset graphic
p2 <- levelplot(r,
margin = FALSE,
colorkey = FALSE,
scales = list(draw = FALSE),
par.settings = GrTheme)
## Create viewports (more info in https://stat.ethz.ch/R-manual/R-devel/library/grid/doc/grid.pdf)
## Main viewport
vp1 <- viewport()
pushViewport(vp1)
print(p1, newpage = FALSE)
## Inset viewport
xi <- 0.3
yi <- 0.6
wi <- 0.3
hi <- 0.2
vp2 <- viewport(x = xi,
y = yi,
height = hi,
width = wi)
pushViewport(vp2)
print(p2, newpage=FALSE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment