Adds a rectangular to the plot.

ggpLayerRect(
  object = "object",
  xrange,
  yrange,
  alpha = 0,
  color = "black",
  size = 1,
  expand = 0,
  persp = "coords",
  img_name = activeImage(object),
  ...
)

Arguments

object

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

xrange, yrange

Vector of length two. Specifies the x- and y-range of the rectangle. E.g. xrange = c(200, 500) results in a rectangle that ranges from 200px to 500px on the x-axis.

This argument works within the SPATA2 distance framework. If values are specified in SI units of length the input is immediately converted to pixel units.

See details and examples of ?is_dist and ?as_unit for more information.

alpha, color, fill, size

Given to ggplot2::geom_rect().

expand

Specifies image expansion. An image that is cropped based on an image annotation centers around the image annotation. If expand = 0, the default, the dimensions of the image, that is width/x-axis and height/y-axis, are set to include only the image annotation area and nothing more. Using expand, the cropped image section can be adjusted. See section Expansion of cropped image sections for more information.

img_name

Character value. The name of the image of interest. If NULL, the active image is chosen by default. Either way, must be one of getImageNames().

...

Additional arguments given to ggplot2::geom_rect().

Value

ggpLayer*()-functions return lists of ggproto objects that can be added to ggplots via the + operator. In most of the cases they are supposed to be added to plots created with the plotSurface*() family.

Examples


library(SPATA2)
library(patchwork)

object <- loadExampleObject("UKF275T")

object <-
 createNumericAnnotations(
   object = object,
   variable = "HM_HYPOXIA",
   threshold = "kmeans_high",
   id = "hypoxia_ann",
   inner_borders = FALSE,
   force1 = TRUE
   )

# range of hypoxia annotation
hr <- getSpatAnnRange(object, id = "hypoxia_ann")

hr_ggpL <- ggpLayerSpatAnnOutline(object, ids = "hypoxia_ann")

plotSurface(object, "HM_HYPOXIA") + hr_ggpL

p_rect <-
 plotImage(object) +
 hr_ggpL +
 ggpLayerRect(object, xrange = hr$x, yrange = hr$y)

p_zoomed <-
 plotImage(object) +
 ggpLayerZoom(object, xrange = hr$x, yrange = hr$y)

p_rect + p_zoomed