This function moves a spatial annotation either in the x or y direction, or both. It allows for selective shifting of outer and/or inner borders of the annotation.

shiftSpatialAnnotation(
  object,
  id,
  outer = TRUE,
  inner = TRUE,
  shift_x = 0,
  shift_y = 0,
  new_id = FALSE,
  overwrite = FALSE
)

Arguments

object

An object of class SPATA2 or, in case of S4 generics, objects of classes for which a method has been defined.

id

Character value specifying the ID of the spatial annotation of interest. If there is only one spatial annotation in the object, the function will default to using it. However, if there are multiple annotations, this argument must be explicitly specified to identify the target annotation.

outer

Logical; if TRUE, the outer border of the annotation is affected.

inner

Logical or numeric; if TRUE, all inner borders are affected. If a numeric value is provided, only the specified inner borders are affected.

shift_x, shift_y

Distance measure. The shift in the x- and/or y-direction. Negative values are also accepted.

new_id

Character value or FALSE. If character, the resulting spatial annotation is stored under a new ID.

overwrite

Logical value. Must be TRUE to allow overwriting.

Value

The updated input object, containing the added, removed or computed results.

Examples

library(SPATA2)
library(patchwork)
library(stringr)

data("example_data")

object <- example_data$object_UKF313T_diet

p1 <- plotImage(object) + ggpLayerSpatAnnOutline(object, ids = "necrotic_area")

plot(p1)

object <- shiftSpatialAnnotation(object, id = "necrotic_area", shift_x = "0.5mm", shift_y = "0.25mm", new_id = "na_shifted")

p2 <- plotImage(object) + ggpLayerSpatAnnOutline(object, ids = "na_shifted")

# compare both
p1 + p2