Skip to contents

This function adds text to frames created with frames_spatial.

Usage

add_text(
  frames,
  labels,
  x,
  y,
  colour = "black",
  size = 3,
  type = "text",
  verbose = TRUE
)

Arguments

frames

an object of class moveVis created with frames_spatial.

labels

character, text to be added to frames. Either a single character value or a character vector of same length as frames.

x

numeric, position of text on the x scale. Either a single numeric value or a numeric vector of same length as frames.

y

numeric, position of text on the y scale. Either a single numeric value or a numeric vector of same length as frames.

colour

character, the text colour(s). Either a single character value or a character vector of same length as frames.

size

numeric, the text size(s). Either a single numeric value or a numeric vector of same length as frames.

type

character, either "text" to draw text or "label" to draw text inside a box.

verbose

logical, if TRUE, messages and progress information are displayed on the console (default).

Value

A frames object of class moveVis.

Author

Jakob Schwalb-Willmann

Examples

library(moveVis)
library(move2)
library(terra)

data("move_data", package = "moveVis")
r <- readRDS(example_data(file = "raster_NDVI.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 text somewhere to all frames:
frames <- frames_spatial(m, r, r_type = "gradient", fade_raster = TRUE) %>%
  add_text("Water area", x = 8.959, y = 47.7305, colour = "white", size = 3)
#> 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 use the ggplot2 "label" type:
frames <- frames_spatial(m, r, r_type = "gradient", fade_raster = TRUE) %>%
  add_text("Water area", x = 8.959, y = 47.7305, colour = "black", size = 3, 
           type = "label")
#> 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]]