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

sbar

scalebar


Description

Add a scalebar to a plot

Usage

sbar(d, xy=NULL, type="line", divs=2, below="", 
    lonlat=NULL, label, adj=c(0.5, -1), lwd=2, xpd=TRUE, ...)

Arguments

d

numeric. Distance covered by the scalebar. In the units of the coordinates of the plot, and in km for angular (longitude/latitude) data; see lonlat

xy

x and y coordinate to place the plot. Can be NULL. Use xy=click() to make this interactive

type

"line" or "bar"

divs

number of divisions for a bar: 2 or 4

below

character. Text to go below scalebar (e.g., "kilometers")

lonlat

logical or NULL. If logical, TRUE indicates if the plot is using longitude/latitude coordinates. If NULL this is guessed from the plot's coordinates

adj

adjustment for text placement

label

vector of three numbers to label the scale bar (beginning, midpoint, end)

lwd

line width for the "line" type scalebar

xpd

logical. If TRUE, the scalebar can be (partly) outside the plot area

...

graphical arguments to be passed to other methods

Value

none

See Also

Examples

f <- system.file("ex/meuse.tif", package="terra")
r <- rast(f)
plot(r)
sbar(1000)
sbar(1000, xy=c(178500, 333500), type="bar", divs=4, cex=.8)

f <- system.file("ex/elev.tif", package="terra")
r <- rast(f)
plot(r, type="interval")
sbar(20, c(6.2, 50.1), type="bar", cex=.8, divs=4)
sbar(15, c(6.3, 50), type="bar", below="km", label=c(0,7.5,15), cex=.8)
sbar(15, c(6.65, 49.9), cex=.8, label=c(0,"km",15))

sbar(15, c(6.65, 49.8), cex=.8, label="15 kilometer", lwd=5)

sbar(15, c(6.65, 49.7), divs=4, cex=.8, below="km")

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.