Plot stored polygons

plotPolygons(
  gobject,
  polygon_name = "selections",
  x,
  spat_unit = "cell",
  polygons = NULL,
  ...
)

Arguments

gobject

A Giotto object with polygon coordinates

polygon_name

name of polygon selections

x

A ggplot2, spatPlot or terra::rast object

spat_unit

spatial unit

polygons

character. Vector of polygon names to plot. If NULL, all polygons are plotted

...

Additional parameters passed to ggplot2::geom_polygon() or graphics::polygon

Value

A ggplot2 image

Examples

## Plot interactive polygons
g <- GiottoData::loadGiottoMini("visium")
#> 1. read Giotto object
#> 2. read Giotto feature information
#> 3. read Giotto spatial information
#> 3.1 read Giotto spatial shape information
#> 3.2 read Giotto spatial centroid information
#> 3.3 read Giotto spatial overlap information
#> 4. read Giotto image information
#> python already initialized in this session
#>  active environment : '/usr/bin/python3'
#>  python version : 3.10
#> checking default envname 'giotto_env'
#> a system default python environment was found
#> Using python path:
#>  "/usr/bin/python3"
my_polygon_coords <- data.frame(
    poly_ID = rep("polygon1", 3),
    sdimx = c(5477, 5959, 4720), sdimy = c(-4125, -2808, -5202)
)

## Add polygon coordinates to Giotto object
my_giotto_polygons <- createGiottoPolygonsFromDfr(my_polygon_coords,
    name = "selections"
)
#>   Selecting col "poly_ID" as poly_ID column
#>   Selecting cols "sdimx" and "sdimy" as x and y respectively
g <- addGiottoPolygons(
    gobject = g,
    gpolygons = list(my_giotto_polygons)
)

## Add polygon cells
g <- addPolygonCells(g)
#> 
#> These column names were already used: in_tissue nr_feats perc_feats total_expr
#>  leiden_clus custom_leiden
#>  and will be overwritten

## Create spatplot
x <- spatPlot2D(g, return_plot = TRUE)


plotPolygons(g, x = x)