Visualisation Gallery

R-CMD-check pkgdown Codecov test coverage License: MIT Lifecycle: experimental

Overview

Every phenoscapR plotting function returns a ggplot object, so you can add themes, facets, or annotations as usual, and they all draw from the global palette system for consistent colours across a figure panel. This gallery shows each one on the bundled example data.

library(phenoscapR)
library(ggplot2)
data(phenoscapR_example)

obj <- phenoscapR_example
obj@meta_data$phenotype <- obj@meta_data$phenotype_true
obj <- NormaliseData(obj, method = "zscore")

# A single tissue for the spatial maps.
a <- obj[obj$sample_id == "tonsil_A", ]
# Cell subsetting invalidates cached local density; compute it on this tissue.
a <- CellDensity(a, radius = 40)
markers <- c("CD20", "CD3", "CD8", "PanCK")

Tissue maps

CellMap() — phenotype map

CellMap(a)

Synthetic tonsil A cell positions coloured by simulated phenotype.

FeaturePlot() — marker intensity in space

FeaturePlot(a, features = markers)

Spatial distributions of normalised CD20, CD3, CD8 and PanCK intensity in synthetic tonsil A.

DensityPlot() — local cell density

DensityPlot(a)

Synthetic tonsil A cell positions coloured by local cell density within radius 40.

SpatialNetworkPlot() — cell-contact graph

a_net <- DelaunayNetwork(a, max_edge = 60)
SpatialNetworkPlot(a_net)

Delaunay network of synthetic tonsil A cells, retaining edges no longer than 60.

Marker distributions

ViolinPlot() and BoxPlot()

ViolinPlot(a, features = markers, group_by = "phenotype")

Violin distributions of four normalised marker intensities by simulated phenotype.

BoxPlot(a, features = markers, group_by = "phenotype")

Box plots of four normalised marker intensities by simulated phenotype.

RidgePlot() and HistogramPlot()

RidgePlot(a, features = markers, group_by = "phenotype")

Distributions of four normalised marker intensities by simulated phenotype.

HistogramPlot(a, feature = "CD20", group_by = "phenotype")

Histograms of normalised CD20 intensity by simulated phenotype.

DotPlot() — mean expression × fraction expressing

DotPlot(a, features = c("CD3", "CD4", "CD8", "CD20", "CD68", "PanCK", "FoxP3"))

Marker expression by simulated phenotype; dot colour shows mean expression and size shows the expressing fraction.

Summaries

MarkerHeatmap() — phenotype signatures

MarkerHeatmap(obj)

Mean normalised marker intensities for each simulated phenotype.

CompositionPlot() — phenotype proportions

CompositionPlot(obj, group_by = "sample_id")

Stacked simulated phenotype proportions in each synthetic section.

InteractionPlot() — co-localisation scores

InteractionPlot(InteractionMatrix(obj, radius = 40))

Pairwise simulated phenotype interaction scores within the synthetic sections at radius 40.

QCPlot() — any metadata pair

QCPlot(a, x = "cell_area", y = "density", colour_by = "phenotype")

Cell area versus local density in synthetic tonsil A, coloured by simulated phenotype.

Dimensionality reductions

Reduce marker space and plot it with DimPlot() / EmbeddingPlot().

obj <- RunPCA(obj, n_pcs = 10)
DimPlot(obj, reduction = "pca", colour_by = "phenotype")

PCA embedding of synthetic cells coloured by simulated phenotype.

# Base SVD is sufficient for this small marker panel and avoids dependence
# on an optional truncated-SVD solver when disconnected groups need PCA init.
obj <- RunUMAP(obj, dims = 10, n_neighbors = 15, seed = 1,
               pca_method = "svd", n_threads = 1)
EmbeddingPlot(obj, reduction = "umap", colour_by = "phenotype")

UMAP embedding of synthetic cells coloured by simulated phenotype.

Theming and palettes

Because each plot is a plain ggplot, standard customisation just works:

CellMap(a) +
  labs(title = "Tonsil A — phenotype map") +
  theme(plot.title = element_text(face = "bold"))

Synthetic tonsil A phenotype map with a customised title.

The package palette is global. Set it once and every plot follows. Any viridis-family option works ("viridis", "inferno", "plasma", "cividis", "rocket", "mako"):

SetPalette("rocket")
CompositionPlot(obj, group_by = "sample_id")

Stacked simulated phenotype proportions in each section using the rocket palette.

PaletteDiscrete(), PaletteContinuous(), and CustomGradient() expose the same colours for use in bespoke plots.

PaletteDiscrete(5)
#> [1] "#4B0055" "#00588B" "#009B95" "#53CC67" "#FDE333"

See also