
Plot density-based tissue compartments alongside the density difference
Source:R/plot_tissue_split.R
plot_tissue_split.Rdsplit_tissue() discards the density images and point patterns it computes
the boundary from, to avoid inflating the mif. plot_tissue_split()
recomputes them on demand, at plot time, from the settings recorded by
split_tissue(), and draws the stored boundary polyline (never a
recontoured one) on top of both a raster of the density difference and a
scatter of the per-cell compartment label.
Arguments
- mif
object of class
mifthat has been throughsplit_tissue()- which
samples to plot:
NULLfor all, or a numeric/character vector indexing/naming elements ofmif$spatial- compartment
which compartment column to colour cells by: the 3-level
"refined_density_compartment"(default) or the 2-level"density_compartment"- panels
which panel(s) to draw:
"both"(default, one faceted plot with the density-difference raster and the compartment scatter side by side),"density"alone, or"compartment"alone- colors
named character vector of colours for
class1,class2and (forcompartment = "refined_density_compartment")"Interface". IfNULL, defaults toRColorBrewer::brewer.pal(3, "Set1")[1:2]for the two classes and"grey20"for"Interface";NA/unclassified cells are always drawn"grey70".- point_size
size passed to
ggplot2::geom_point()for the compartment panel- raster_max_pixels
the density raster is recomputed at plot time (see Details) at up to this many pixels; above the cap resolution is capped for display only – the drawn boundary line is unaffected and stays exact.
- workers
number of cores to use, one sample per core
- filename, path
if
filenameis given, every requested plot is also written to a single PDF atfile.path(path, filename)(pathdefaults to the working directory; a trailing.pdfinfilenameis not doubled).- settings
provenance normally read from
attr(mif$derived$density_boundary, "call_info"), whichsplit_tissue()attaches. That attribute does not survive[subsetting ordplyr::bind_rows()(e.g. aftermerge_mifs()disagrees across mifs), so pass the settings list explicitly to recover from that: a list withclassifier,class1,class2,sigma,eps,interface_width,xloc,yloc,filter_density,rescale,min_density,hard_threshold,sample_idandspatialTIME_version.rescale,min_densityandhard_thresholdmay be omitted: they are backfilled to the behaviour that predated them (FALSE, off,FALSE), so provenance recorded before those arguments existed still replots correctly.- ...
accepts no arguments; present only so that a mistyped named argument above produces an informative "Unknown argument" error instead of being silently absorbed.
Value
a named list of ggplot objects, one per requested sample, named
like mif$spatial – not the mif. Unlike plot_immunoflo(), this
deliberately does not attach the plots to mif$derived: each plot
captures a raster data frame that can be as large as the sample itself,
and merge_mifs()'s handling of list-valued derived slots is fragile
enough already (see NEWS.md) without doubling the exposure.
Examples
library(dplyr)
x <- create_mif(clinical_data = example_clinical %>%
mutate(deidentified_id = as.character(deidentified_id)),
sample_data = example_summary %>%
mutate(deidentified_id = as.character(deidentified_id)),
spatial_list = example_spatial[1],
patient_id = "deidentified_id",
sample_id = "deidentified_sample")
x <- split_tissue(x, classifier = "Classifier.Label",
class1 = "Tumor", class2 = "Stroma",
sigma = 40, interface_width = 100)
plots <- plot_tissue_split(x)