scalebarparams: Get Scale Bar Parameters

View source: R/scalebar.R

scalebarparamsR Documentation

Get Scale Bar Parameters

Description

Get default scale bar parameters based on the current plot (i.e. par("usr")). The algorithm attempts to detect the best equally divisable distance to use for the scale bar, and returns a list object with attributes that allow any type of scale bar to be drawn. The only way to manipulate the values chosen by the algorithm is to change the widthhint argument. For generic XY plots, pass plotunit.

Usage

scalebarparams(
  plotunit = NULL,
  plotepsg = NULL,
  widthhint = 0.25,
  unitcategory = "metric",
  extents = graphics::par("usr")
)

Arguments

plotunit

The unit which the current plot is plotted in, one of cm, m, km, in, ft, mi. or latlon. This parameter is optional if plotepsg is passed.

plotepsg

The projection of the current plot. If extents are valid lat/lons, the projection is assumed to be lat/lon (EPSG:4326), or Spherical Mercator otherwise (EPSG:3857). This is done to work seamlessly with OpenStreetMap packages.

widthhint

The fraction of the plottable width which the scale bar should (mostly) occupy.

unitcategory

One of "metric" or "imperial"

extents

The plot extents

Value

a list of parameters: $widthu (width of the scalebar in human readable units); $unit (the human readable unit); $majordivu (the size of the divisions in human readable units); $majordivs (the number of divisions); $widthplotunit (width of the scalebar in plotting units); $majordivplotunit (the width of divisions in plotting units); $labeltext (label text); and extents the user extents (par('usr')) that were used to calculate the parameters.

See Also

addscalebar

Examples

plot(1:5, 1:5, asp=1)
scalebarparams(plotunit="m")


prettymapr documentation built on May 29, 2024, 5:38 a.m.