Creates a scale bar. By default, the coordinate units are assumed to be meters, and the map units in kilometers. This can be changed in tm_shape
.
Usage
tm_scale_bar(
breaks = NULL,
width = NA,
text.size = 0.5,
text.color = NA,
color.dark = "black",
color.light = "white",
lwd = 1,
position = NA,
bg.color = NA,
bg.alpha = NA,
just = NA,
size = NULL
)
Arguments
- breaks
breaks of the scale bar. If not specified, breaks will be automatically be chosen given the prefered
width
of the scale bar. Not available for view mode.- width
(preferred) width of the scale bar. Only applicable when
breaks=NULL
. In plot mode, it corresponds the relative width; the default is 0.25 so one fourth of the map width. In view mode, it corresponds to the width in pixels; the default is 100.- text.size
relative text size (which is upperbound by the available label width)
- text.color
color of the text. By default equal to the argument
attr.color
oftm_layout
.- color.dark
color of the dark parts of the scale bar, typically (and by default) black.
- color.light
color of the light parts of the scale bar, typically (and by default) white.
- lwd
line width of the scale bar
- position
position of the scale bar Vector of two values, specifying the x and y coordinates. Either this vector contains "left", "LEFT", "center", "right", or "RIGHT" for the first value and "top", "TOP", "center", "bottom", or "BOTTOM" for the second value, or this vector contains two numeric values between 0 and 1 that specifies the x and y value of the left bottom corner of the scale bar. The uppercase values correspond to the position without margins (so tighter to the frame). The default value is controlled by the argument
"attr.position"
oftm_layout
.- bg.color
Background color
- bg.alpha
Transparency of the background color. Number between 0 (totally transparent) and 1 (not transparent). By default, the alpha value of the
bg.color
is used (normally 1).- just
Justification of the attribute relative to the point coordinates. The first value specifies horizontal and the second value vertical justification. Possible values are:
"left"
,"right"
,"center"
,"bottom"
, and"top"
. Numeric values of 0 specify left/bottom alignment and 1 right/top alignment. This option is only used, ifposition
is specified by numeric coordinates. The default value is controlled by the argument"attr.just"
oftm_layout
.- size
deprecated: renamed to text.size
Examples
current.mode <- tmap_mode("plot")
#> tmap mode set to plotting
data(NLD_muni)
qtm(NLD_muni, theme = "NLD") + tm_scale_bar(position=c("left", "bottom"))
#> old-style crs object detected; please recreate object with a recent sf::st_crs()
#> old-style crs object detected; please recreate object with a recent sf::st_crs()
#> old-style crs object detected; please recreate object with a recent sf::st_crs()
#> old-style crs object detected; please recreate object with a recent sf::st_crs()
#> old-style crs object detected; please recreate object with a recent sf::st_crs()
# restore current mode
tmap_mode(current.mode)
#> tmap mode set to plotting