
Add scalebar to frames
add_scalebar.Rd
This function adds a scalebar to frames created with frames_spatial
.
Usage
add_scalebar(
frames,
distance = NULL,
height = 0.015,
position = "bottomleft",
x = NULL,
y = NULL,
colour = "black",
label_margin = 1.2,
units = "km",
verbose = TRUE
)
Arguments
- frames
an object of class
moveVis
created withframes_spatial
.- distance
numeric, optional. Distance displayed by the scalebar (in either km or miles defined by argument
units
) By default, the displayed distance is calculated automatically.- height
numeric, height of the scalebar in a range from 0 to 1 as the proportion of the overall height of the frame map. Default is 0.015.
- position
character, position of the scalebar on the map. Either
"bottomleft", "upperleft", "upperright", "bottomright"
. Ignored, ifx
andy
are set.- x
numeric, position of the bottom left corner of the scalebar on the x axis. If not set,
position
is used to calculate the position of the scalebar.- y
numeric, position of the bottom left corner of the scalebar on the y axis. If not set,
position
is used to calculate the position of the scalebar.- colour
character, colour of the distance labels. Default is
"black"
.- label_margin
numeric, distance of the labels to the scalebar as a proportion of the height of the scalebar (e.g. if set to 2, the labels will be positioned with a distance to the scalebar of twice the scalebar height).
- units
character, either "km" for kilometers or "miles" for miles.
- verbose
logical, if
TRUE
, messages and progress information are displayed on the console (default).
Examples
library(moveVis)
library(move2)
library(terra)
data("move_data", package = "moveVis")
r <- readRDS(example_data(file = "basemap_data.rds"))
# align movement
m <- align_move(move_data, res = units::set_units(4, "min"))
#> Temporal resolution of 4 [min] is used to align trajectories.
# create frames and add scaleebar
frames <- frames_spatial(m, r, r_type = "gradient", fade_raster = TRUE) %>%
add_scalebar()
#> Processing input data...
#> Approximated animation duration: ≈ 7.52s at 25 fps using 188 frames
#> CRS (geodetic): WGS 84
#> Assigning raster maps to frames...
frames[[100]]
# or in white at another position
frames <- frames_spatial(m, r, r_type = "gradient", fade_raster = TRUE) %>%
add_scalebar(colour = "white", position = "bottomright")
#> Processing input data...
#> Approximated animation duration: ≈ 7.52s at 25 fps using 188 frames
#> CRS (geodetic): WGS 84
#> Assigning raster maps to frames...
frames[[100]]
# or with another height
frames <- frames_spatial(m, r, r_type = "gradient", fade_raster = TRUE) %>%
add_scalebar(colour = "white", position = "bottomright", height = 0.025)
#> Processing input data...
#> Approximated animation duration: ≈ 7.52s at 25 fps using 188 frames
#> CRS (geodetic): WGS 84
#> Assigning raster maps to frames...
frames[[100]]