mf_scale: Plot a scale bar

View source: R/mf_scale.R

mf_scaleR Documentation

Plot a scale bar

Description

Plot a scale bar.

Usage

mf_scale(
  size,
  pos = "bottomright",
  lwd = 1.5,
  cex = 0.6,
  col,
  crs_units = "m",
  scale_units = "km",
  x,
  unit
)

Arguments

size

size of the scale bar in scale units (scale_units, default to km). If size is not set, an automatic size is used (1/10 of the map width).

pos

position. It can be one of 'bottomright', 'bottomleft', 'interactive' or a vector of two coordinates in map units (c(x, y)).

lwd

line width of the scale bar

cex

size of the scale bar text

col

color of the scale bar (line and text)

crs_units

units used in the CRS of the currently plotted layer. Possible values are "m" and "ft" (see Details).

scale_units

units used for the scale bar. Can be "mi" for miles, "ft" for feet, "m" for meters, or "km" for kilometers (default).

x

object of class crs, sf or sfc. If set, the CRS of x will be used instead of crs_units to define CRS units.

unit

deprecated, use scale_units instead

Details

Most CRS use the meter as unit. Some US CRS use feet or US survey feet. If unsure of the unit used in the CRS you can use the x argument of the function. Alternatively, you can use sf::st_crs(zz, parameters = TRUE)$units_gdal to see which units are used in the zz layer.

This scale bar does not work on unprojected (long/lat) maps.

Value

No return value, a scale bar is displayed.

Examples

mtq <- mf_get_mtq()
mf_map(mtq)
mf_scale()

library(sf)
nc <- st_read(system.file("shape/nc.shp", package = "sf"))[1, ]

nc_foot <- st_transform(nc, 2264) # NC state plane, US foot
mf_map(nc_foot)
mf_scale(size = 5, crs_units = "ft", scale_units = "mi")
mf_map(nc_foot)
mf_scale(size = 5, x = nc_foot, scale_units = "mi")

nc_meter <- st_transform(nc, 32119) # NC state plane, m
mf_map(nc_meter)
mf_scale(size = 5, crs_units = "m", scale_units = "mi")
mf_scale(size = 5, crs_units = "m", scale_units = "km", pos = "bottomleft")

mapsf documentation built on May 29, 2024, 7:12 a.m.