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
.
scalebarparams(
plotunit = NULL,
plotepsg = NULL,
widthhint = 0.25,
unitcategory = "metric",
extents = graphics::par("usr")
)
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.
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.
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.
The fraction of the plottable width which the scale bar should (mostly) occupy.
One of "metric" or "imperial"
The plot extents
addscalebar
plot(1:5, 1:5, asp=1)
scalebarparams(plotunit="m")
Run the code above in your browser using DataLab