addSpatialAnnotation | R Documentation |
Adds spatial annotations using polygon data.frames.
addSpatialAnnotation(object, ...)
## S4 method for signature 'SPATA2'
addSpatialAnnotation(
object,
tags,
area,
id = NULL,
overwrite = FALSE,
class = "SpatialAnnotation",
...
)
## S4 method for signature 'SpatialData'
addSpatialAnnotation(
object,
tags,
area,
id = NULL,
overwrite = FALSE,
class = "SpatialAnnotation",
...
)
object |
An object of class |
... |
Additional slot content given to |
tags |
A character vector of tags for the spatial annotation. |
area |
A named list of data.frames with the numeric variables x and y or x_orig and y_orig. Observations correspond to the vertices of the polygons that are needed to represent the spatial annotation. Must contain exactly one slot named outer which sets the outer border of the spatial annotation. Can contain multiple slots named inner (suffixed) with numbers that correspond to inner polygons - holes within the annotation. |
id |
Character value. The ID of the spatial annotation. If |
overwrite |
Logical value. Must be |
The updated input object, containing the added, removed or computed results.
getCoordsDf()
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.