Skip to contents

Scatter plot of sample activity on one factor against another, coloured or shaped by sample metadata, to see how programs co-occur across samples.

Usage

plot_factor_scatter(
  fit,
  factors,
  metadata = NULL,
  color = NULL,
  shape = NULL,
  representation = NULL,
  max_samples = 2000L,
  seed = 1L
)

Arguments

fit

Native fit or a view from standardize_factors().

factors

Exactly two character factor IDs, x then y.

metadata

Optional data frame with a sample column matching the activity row names; needed only with group.

color, shape

Optional names of metadata columns for point colour and point shape. Shape needs a discrete column.

representation

For a native fit: a matched view or standardize_factors() settings.

max_samples

Maximum samples drawn for display (default 2000).

seed

Integer seed for the sample draw (default 1), recorded in the metadata.

Value

A ggplot object; $data has one row per displayed sample with sample, x, y and any metadata columns used, plus metadata attributes.

Details

Origin: NEW_QOL / none. Credits MOFA2 factor-scatter display workflow; use factor_provenance("plot_factor_scatter") for audited sources and runtime versions. Input units and basis are retained; display/conditional results do not establish biological replication.

Author

Mikhael Manurung. Conceptual workflow: MOFA2 plot_factors (Ricard Argelaguet, Damien Arnol, Danila Bredikhin, Britta Velten). Full source and dependency credits: https://github.com/mdmanurung/flashier-utils/blob/main/CREDITS.md.

Examples

set.seed(3)
X <- tcrossprod(matrix(rnorm(48), 24, 2), matrix(rnorm(32), 16, 2)) +
  matrix(rnorm(384, sd = 0.2), 24, 16)
dimnames(X) <- list(paste0("s", 1:24), paste0("g", 1:16))
fit <- fit_ebmf(X, "rows",
  max_factors = 2, seed = 4, verbose = 0,
  ebnm_fn = list(ebnm::ebnm_normal, ebnm::ebnm_point_laplace),
  nullcheck = FALSE, backfit = TRUE, feature_scale = "simulated_centered_intensity"
)
view <- standardize_factors(fit)
metadata <- data.frame(sample = rownames(X), group = rep(c("A", "B"), each = 12))
plot_factor_scatter(view, c("F1", "F2"), metadata = metadata, color = "group")