Show the input values of a factor's strongest features across samples ordered by that factor's activity, as a heatmap or as per-feature scatter plots. Use it to check that a factor reflects a pattern visible in the data and not only in the fitted coordinates. The data are displayed in the units you supply; z-scoring is a display choice recorded in the metadata.
Usage
plot_factor_data(
fit,
X,
factor,
n = 20L,
style = "heatmap",
sample_side = NULL,
representation = NULL,
metadata = NULL,
group = NULL,
direction = "absolute",
scale = "feature_z",
max_samples = 2000L,
seed = 1L
)Arguments
- fit
Native fit or a view from
standardize_factors().- X
Named numeric matrix or double sparse Matrix of the observed data, normally the matrix the model was fitted on. Samples are on the side named by
sample_side.- factor
One factor ID, e.g.
"F1".- n
Number of strongest features to show (default 20).
- style
"heatmap"(default) or"scatter"(activity against each feature's values, one panel per feature).- sample_side
"rows"or"columns"ofX.NULL(default) uses the side recorded in the view.- representation
For a native fit: a matched view or
standardize_factors()settings.- metadata
Optional data frame with a
samplecolumn; needed withgroup.- group
Optional
metadatacolumn used to facet the heatmap or colour the scatter.- direction
"absolute"(default),"positive"or"negative": which features count as strongest.- scale
"feature_z"(default; centre and scale each feature for the heatmap, display only) or"none"(supplied units). Ignored for scatter.- 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 sample, feature, value (and
activity for scatter), with display and basis metadata attributes.
Details
Origin: NEW_QOL / none. Credits MOFA2 data-level display workflow; use factor_provenance("plot_factor_data") 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_data_heatmap and plot_data_scatter (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)
plot_factor_data(view, X, factor = "F1", n = 6)
plot_factor_data(view, X, factor = "F1", n = 4, style = "scatter")