| ggpLayerImage | R Documentation | 
Creates ggplot2 layer with the histology image as a raster.
ggpLayerImage(object, ...)
## S4 method for signature 'SPATA2'
ggpLayerImage(
  object,
  img_name = activeImage(object),
  transform = TRUE,
  img_alpha = 1,
  scale_fct = 1,
  ...
)
## S4 method for signature 'SpatialData'
ggpLayerImage(
  object,
  img_name = activeImage(object),
  transform = TRUE,
  img_alpha = 1,
  scale_fct = 1,
  ...
)
## S4 method for signature 'HistoImage'
ggpLayerImage(object, transform = TRUE, scale_fct = 1, img_alpha = 1, ...)
## S4 method for signature 'SpatialAnnotation'
ggpLayerImage(object, img_alpha = 1, rescale_axes = TRUE, scale_fct = 1, ...)
## S4 method for signature 'Image'
ggpLayerImage(object, scale_fct = 1, img_alpha = 1, ...)
## S4 method for signature 'data.frame'
ggpLayerImage(object, fill_by, img_alpha = 1)
| object | An object of class  | 
| ... | Used to absorb deprecated arguments or functions. | 
| img_name | Character value. The name of the image of interest.
If  | 
| transform | Logical value. Ignored if no images exist in the object. If  | 
| img_alpha | Numeric value. Sets the transparency for the image. | 
The image is plotted via ggplot2::geom_raster() by mapping the pixel position
to the x-axis and the y-axis. See section Image visualization
with ggplot2 for more details.
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.
When comparing the output of ggplot() + ggpLayerImage() with other image plotting functions,
you may notice that the image appears horizontally flipped when plotted using ggpLayerImage().
This behavior is due to the use of a Cartesian coordinate system in SPATA2, where a pixel
with coordinates c(width = 1, height = 1) is plotted on the left side at the bottom.
In contrast, functions like EBImage::display() or graphics::plot() use an image space coordinate system,
where pixel heights start from the top. Consequently, in image space, pixel c(width = 1, height = 1)
is displayed on the top resulting in mirror inverted visualization of the image.
We chose to use a Cartesian coordinate system in SPATA2 because we believe it provides a more intuitive
framework for the spatial alignment of tissue, spatial annotations, spatial trajectories,
barcoded sots, single cells, etc. where coordinates in the corresponding data.frames are provided
in form of x- and y-variables. See getCoordsDf(), getImgAnnOutlineDf(), getTissueOutlineDf() etc.
If you prefer to view your image in the regular orientation, you can use the flipAll() function on your object,
specifying axis = "horizontal", to reverse this effect.
library(SPATA2)
library(tidyverse)
data("example_data")
object <- loadExampleObject("UKF275T")
ggplot() +
 ggpLayerImage(object)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.