Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

inset

Make an inset map


Description

Make an inset map

Usage

## S4 method for signature 'SpatVector'
inset(x, e, loc="", scale=0.2, background="white", border="black", box=NULL, pbx, ...)

## S4 method for signature 'SpatRaster'
inset(x, e, loc="", scale=0.2, background="white", border="black", box=NULL, pbx, ...)

Arguments

x

SpatVector, SpatRaster

e

SpatExtent to set the size and location of the inset. Or missing

loc

character. One of "bottomright", "bottom", "bottomleft", "left", "topleft", "top", "topright", "right", "center"

scale

numeric. The relative size of the inset, used when x is missing

background

color for the background of the inset. Use NA for no background color

border

color for the border around the inset. Use NA for no border

box

SpatExtent or missing, to draw a box on the inset

pbx

list with graphical arguments for the box

...

additional arguments passed to plot for the drawing of x

Value

scaled and shifted SpatVector or SpatRaster (invisibly)

See Also

Examples

f <- system.file("ex/lux.shp", package="terra")
v <- vect(f)
x <- v[v$NAME_2 == "Diekirch", ]

plot(x, density=10, col="blue")
inset(v)

cols <- rep("light grey", 12)
cols[2] <- "red"
e <- ext(c(6.2, 6.3, 49.9, 50))
b <- ext(x)+0.02
inset(v, e=e, col=cols, box=b)

# with a SpatRaster
ff <- system.file("ex/elev.tif", package="terra")
r <- rast(ff)
r <- crop(r, ext(x) + .01)
plot(r, type="int", mar=c(2,2,2,2), plg=list(x="topright"))
lines(v, lwd=1.5)
lines(x, lwd=2.5)
inset(v, col=cols, loc="topleft", scale=0.15)

# a more complex one
plot(r, plg=list(title="meter\n", shrink=.2, cex=.8))
lines(v, lwd=4, col="white")
lines(v, lwd=1.5)
lines(x, lwd=2.5)
text(x, "NAME_2", cex=1.5, halo=TRUE)
sbar(6, c(6.04, 49.785), type="bar", below="km", label=c(0,3,6), cex=.8)
s <- inset(v, col=cols, box=b, scale=.2, loc="topright", background="light yellow",
	pbx=list(lwd=2, lty=5, col="blue"))

# note the returned inset SpatVector
s

terra

Spatial Data Analysis

v1.2-10
GPL (>= 3)
Authors
Robert J. Hijmans [cre, aut] (<https://orcid.org/0000-0001-5872-2872>), Roger Bivand [ctb] (<https://orcid.org/0000-0003-2392-6140>), Karl Forner [ctb], Jeroen Ooms [ctb] (<https://orcid.org/0000-0002-4035-0289>), Edzer Pebesma [ctb] (<https://orcid.org/0000-0001-8049-7069>)
Initial release
2021-05-12

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.