-
-
Save johnbaums/c44a0423cd88da27f19a85846d4121ad to your computer and use it in GitHub Desktop.
Inset graphics with rasterVis and grid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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