| Title: | SpatialData visualization |
|---|---|
| Description: | Visualization suit for 'spatialdataR'. Current functionality includes handling of multiscale 'images', visualizing 'labels', 'points', and 'shapes'. For the latter, POINT, POLYGON, and MULTIPOLYGON geometries are supported. For all but 'images', there is support to pass information from annotation 'tables' as aesthetics (e.g., 'colData' or 'assay' data). |
| Authors: | Helena L. Crowell [aut, cre] (ORCID: <https://orcid.org/0000-0002-4801-1767>), Artür Manukyan [aut] (ORCID: <https://orcid.org/0000-0002-0441-9517>), Hugo Gruson [aut] (ORCID: <https://orcid.org/0000-0002-4094-1476>), Charlotte Soneson [aut] (ORCID: <https://orcid.org/0000-0003-3833-2169>), Michael Stadler [aut] (ORCID: <https://orcid.org/0000-0002-2269-4934>), Vince Carey [aut] (ORCID: <https://orcid.org/0000-0003-4046-0063>) |
| Maintainer: | Helena L. Crowell <[email protected]> |
| License: | Artistic-2.0 |
| Version: | 0.99.9 |
| Built: | 2026-10-09 16:31:16 UTC |
| Source: | https://github.com/BiocStaging/SpatialData.plot |
data were retrieved on Nov. 11th, 2024, from here.
a SpatialData .zarr store of toy example data with all types of
elements represented: (multiscale) RGB image, (multiscale) label,
point, circle and (multi)polygon shape, table annotation.
In addition, all types of coordinate transformations are represented:
identity, scale, translation, affine, and sequence.
x <- file.path("extdata", "blobs.zarr") x <- system.file(x, package="spatialdataR") (x <- readSpatialData(x))x <- file.path("extdata", "blobs.zarr") x <- system.file(x, package="spatialdataR") (x <- readSpatialData(x))
Add image layer to SpatialData plot
plotImage( i = 1, j = NULL, k = NULL, ch = NULL, c = NULL, cl = NULL, t = NULL, z = NULL, x = NULL )plotImage( i = 1, j = NULL, k = NULL, ch = NULL, c = NULL, cl = NULL, t = NULL, z = NULL, x = NULL )
i |
Index or name of image to plot. |
j |
Index or name of coordinate transformation to use. If |
k |
Index of the scale to render; by default (NULL), will auto-select scale in order to minimize memory-usage and blurring for a target size of 800 x 800px; use Inf to plot the lowest resolution available. |
ch |
Image channel(s) to be used for plotting (defaults to
the first channel(s) available); use |
c |
Character vector; colors to use for each channel. |
cl |
List of length-2 numeric vectors (non-negative, increasing);
specifies channel-wise contrast limits - defaults to [0, 1] for all
(ignored when |
t, z
|
Integer scalar to indicate a specific time- or z-slice; if left unspecified (default NULL), will perform a max-projection. |
x |
|
An object of type sd_image, which can be added to an
existing ggplot.
x <- file.path("extdata", "blobs.zarr") x <- system.file(x, package="spatialdataR") x <- readSpatialData(x, tables=FALSE) ms <- lapply(seq(3), \(.) plotSpatialData(x) + plotImage(2, k=.)) patchwork::wrap_plots(ms) # custom colors cmy <- c("cyan", "magenta", "yellow") plotSpatialData(x) + plotImage(c=cmy) # contrast limits cl <- rep(list(c(0, 1/3)), 3) plotSpatialData(x, ct="global") + plotImage(k=1, c=cmy, cl=cl) + plotShape(i="blobs_circles", fill="pink") + plotPoint(i="blobs_points", colour="instance_id")x <- file.path("extdata", "blobs.zarr") x <- system.file(x, package="spatialdataR") x <- readSpatialData(x, tables=FALSE) ms <- lapply(seq(3), \(.) plotSpatialData(x) + plotImage(2, k=.)) patchwork::wrap_plots(ms) # custom colors cmy <- c("cyan", "magenta", "yellow") plotSpatialData(x) + plotImage(c=cmy) # contrast limits cl <- rep(list(c(0, 1/3)), 3) plotSpatialData(x, ct="global") + plotImage(k=1, c=cmy, cl=cl) + plotShape(i="blobs_circles", fill="pink") + plotPoint(i="blobs_points", colour="instance_id")
Add label layer to SpatialData plot
plotLabel( i = 1, j = NULL, k = NULL, c = NULL, a = 0.5, pal = NULL, nan = NA, assay = 1, t = NULL, z = NULL, x = NULL )plotLabel( i = 1, j = NULL, k = NULL, c = NULL, a = 0.5, pal = NULL, nan = NA, assay = 1, t = NULL, z = NULL, x = NULL )
i |
Index or name of label to plot. |
j |
Index or name of coordinate transformation to use. If |
k |
Index of the scale to render; by default (NULL), will auto-select scale in order to minimize memory-usage and blurring for a target size of 800 x 800px; use Inf to plot the lowest resolution available. |
c |
determines label colors;
the default (NULL), gives a binary image of whether or not a
pixel is non-zero; alternatively, a character string specifying
a |
a |
scalar numeric in [0, 1]; alpha value passed to |
pal |
character vector; color for discrete/continuous values (interpolated automatically when insufficient values are provided). When left unspecified, color will be sampled at random. |
nan |
character string; color for missing values (hidden by default). |
assay |
character string;
in case of |
t, z
|
Integer scalar to indicate a specific time- or z-slice; if left unspecified (default NULL), will perform a max-projection. |
x |
|
An object of type sd_label, which can be added to an
existing ggplot.
x <- file.path("extdata", "blobs.zarr") x <- system.file(x, package="spatialdataR") x <- readSpatialData(x) i <- "blobs_labels" p <- plotSpatialData(x) # simple binary image p + plotLabel(i) # mock up some extra data t <- getTable(x, i) t$id <- sample(letters, ncol(t)) table(x) <- t # coloring by 'colData' t <- getTable(x, i) t$id <- sample(letters, ncol(t)) table(x) <- t plotSpatialData(x) + plotLabel(i=i, c="id") # coloring by 'assay' data plotSpatialData(x) + plotLabel(i=i, c="channel_1_sum", pal=c("lavender", "blue"))x <- file.path("extdata", "blobs.zarr") x <- system.file(x, package="spatialdataR") x <- readSpatialData(x) i <- "blobs_labels" p <- plotSpatialData(x) # simple binary image p + plotLabel(i) # mock up some extra data t <- getTable(x, i) t$id <- sample(letters, ncol(t)) table(x) <- t # coloring by 'colData' t <- getTable(x, i) t$id <- sample(letters, ncol(t)) table(x) <- t plotSpatialData(x) + plotLabel(i=i, c="id") # coloring by 'assay' data plotSpatialData(x) + plotLabel(i=i, c="channel_1_sum", pal=c("lavender", "blue"))
Add point layer to SpatialData plot
plotPoint(i = 1, j = NULL, x = NULL, ...)plotPoint(i = 1, j = NULL, x = NULL, ...)
i |
Index or name of point to plot. |
j |
Index or name of coordinate transformation to use. If |
x |
|
... |
Optional aesthetic arguments passed to |
An object of type sd_point, which can be added to an
existing ggplot.
x <- file.path("extdata", "blobs.zarr") x <- system.file(x, package="spatialdataR") x <- readSpatialData(x) i <- "blobs_points" p <- plotSpatialData(x) p + plotPoint(i=i) # simple p + plotPoint(i=i, colour="genes") # discrete p + plotPoint(i, colour="instance_id") # continuousx <- file.path("extdata", "blobs.zarr") x <- system.file(x, package="spatialdataR") x <- readSpatialData(x) i <- "blobs_points" p <- plotSpatialData(x) p + plotPoint(i=i) # simple p + plotPoint(i=i, colour="genes") # discrete p + plotPoint(i, colour="instance_id") # continuous
Add shape layer to SpatialData plot
plotShape(i = 1, j = NULL, assay = 1, x = NULL, ...)plotShape(i = 1, j = NULL, assay = 1, x = NULL, ...)
i |
Index or name of shape to plot. |
j |
Index or name of coordinate transformation to use. If |
assay |
Character string; in case of |
x |
|
... |
Optional aesthetic arguments passed to |
An object of type sd_shape, which can be added to an
existing ggplot.
x <- file.path("extdata", "blobs.zarr") x <- system.file(x, package="spatialdataR") x <- readSpatialData(x) # shapes p <- plotSpatialData(x) a <- p + plotShape(i="blobs_polygons") b <- p + plotShape(i="blobs_multipolygons") c <- p + plotShape(i="blobs_circles") patchwork::wrap_plots(a, b, c) # layered p + plotShape("blobs_circles", fill="pink") + plotShape("blobs_polygons", colour="red") patchwork::wrap_plots(a, b)x <- file.path("extdata", "blobs.zarr") x <- system.file(x, package="spatialdataR") x <- readSpatialData(x) # shapes p <- plotSpatialData(x) a <- p + plotShape(i="blobs_polygons") b <- p + plotShape(i="blobs_multipolygons") c <- p + plotShape(i="blobs_circles") patchwork::wrap_plots(a, b, c) # layered p + plotShape("blobs_circles", fill="pink") + plotShape("blobs_polygons", colour="red") patchwork::wrap_plots(a, b)
Initialize an empty ggplot for a SpatialData object. This function is typically combined with one or more calls to add specific plot layers.
plotSpatialData(x = NULL, ct = NULL)plotSpatialData(x = NULL, ct = NULL)
x |
A SpatialData object. |
ct |
The name of a coordinate transformation to use for the plot. |
A ggplot object.
x <- file.path("extdata", "blobs.zarr") x <- system.file(x, package="spatialdataR") x <- readSpatialData(x, tables=FALSE) ms <- lapply(seq(3), \(.) plotSpatialData(x) + plotImage(i=2, k=.)) patchwork::wrap_plots(ms)x <- file.path("extdata", "blobs.zarr") x <- system.file(x, package="spatialdataR") x <- readSpatialData(x, tables=FALSE) ms <- lapply(seq(3), \(.) plotSpatialData(x) + plotImage(i=2, k=.)) patchwork::wrap_plots(ms)
scalebar will get the axis unit and scale information from the
closest preceding layer where this information is present. Therefore,
the placement of scalebar in the sequence of layers is important.
scalebar(len = NULL, col = "red", lwd = 1, xrel = 0.05, yrel = 0.05)scalebar(len = NULL, col = "red", lwd = 1, xrel = 0.05, yrel = 0.05)
len |
scalar numeric giving the length of the scalebar
in physical coordinate space; the unit will be extracted
from the data's Zarr specifications (see |
col |
string indicating the color to use for the scalebar. |
lwd |
scalar numeric indicating the linewidth to use for the scalebar. |
xrel, yrel
|
scalar numeric indicating relative position of the scalebar. |
length-two list of ggplot2::annotate() layers corresponding to
scalebar line (geom="segment") and unit label (geom="text")
zs <- file.path("extdata", "blobs.zarr") zs <- system.file(zs, package="spatialdataR") sd <- readSpatialData(zs, tables=FALSE) # mock unit (data misses specification!) md <- meta(image(sd, 2)) md$multiscales[[1]]$axes[[3]]$unit <- "micron" sd$images[[2]]@meta <- md plotSpatialData(sd) + plotImage(i=2) + scalebar(len=10)zs <- file.path("extdata", "blobs.zarr") zs <- system.file(zs, package="spatialdataR") sd <- readSpatialData(zs, tables=FALSE) # mock unit (data misses specification!) md <- meta(image(sd, 2)) md$multiscales[[1]]$axes[[3]]$unit <- "micron" sd$images[[2]]@meta <- md plotSpatialData(sd) + plotImage(i=2) + scalebar(len=10)