addInnerBorder | R Documentation |
These methods allow the addition of an inner border to spatial annotations, creating holes.
addInnerBorder(object, ...)
## S4 method for signature 'SPATA2'
addInnerBorder(object, id, border_df, new_id = FALSE, overwrite = FALSE, ...)
## S4 method for signature 'SpatialAnnotation'
addInnerBorder(object, border_df, ...)
object |
An object of class |
... |
Used to absorb deprecated arguments or functions. |
id |
Character value. The ID of the spatial annotation to which the hole is added. |
border_df |
A data.frame that contains the x- and y- positions of the vertices of the polygon that corresponds to the borders of the whole. See details for input requirements. |
new_id |
If character value, stores the resulting spatial annotatiton under the specified ID. |
overwrite |
Logical value. Must be |
If used on a SpatialAnnotation
directly, the variables of border_df
should
be called x_orig and y_orig and should be scaled correspondingly. If
used with the SPATA2
object, the variables can be called x and y, too.
In that case, the function assumes that the coordinates are scaled to the
image that is currently active and creates x_orig and y_orig accordingly.
The updated input object, containing the added, removed or computed results.
activeImage()
, SpatialAnnotation
library(SPATA2)
library(tidyverse)
data("example_data")
object <- example_data$object_UKF275T_diet
create_circle_polygon <- function(p, r, n) {
angles <- seq(0, 2 * pi, length.out = n + 1)
x_coords <- p[1] + r * cos(angles)
y_coords <- p[2] + r * sin(angles)
polygon_df <- tibble::tibble(x = x_coords, y = y_coords)
return(polygon_df)
}
center <-
getCoordsDf(object)[c("x", "y")] %>%
map_dbl(.f = mean)
area_circle <- create_circle_polygon(center, r = 75, n = 100)
print(area_circle)
object <- addSpatialAnnotation(object, area = list(outer = area_circle), id = "circle")
plotSpatialAnnotations(object, ids = "circle")
hole <- create_circle_polygon(center, r = 25, n = 100)
object <- addInnerBorder(object, id = "circle", border_df = hole, new_id = "circle_with_hole")
plotSpatialAnnotations(object, ids = c("circle", "circle_with_hole"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.