Plot every feature effect of a factor, ranked, with the top features labelled
Source:R/plot-suite.R
plot_factor_weights.RdRank all features of one or more factors by signed effect and label the
strongest ones, so you see the whole distribution and not only a selection.
This is the view of a factor's loadings that plot_factor_features() cuts
down to n features. Display only: effects keep their declared units.
Usage
plot_factor_weights(
fit,
factors,
representation = NULL,
n_label = 10L,
direction = "absolute",
scale = "none"
)Arguments
- fit
Native fit or a view from
standardize_factors().- factors
Character factor IDs to display, e.g.
c("F1", "F2"); one panel per factor.- representation
For a native fit: a matched view or
standardize_factors()settings.- n_label
Number of features to label per factor (default 10).
- direction
"absolute"(default),"positive"or"negative": which features are labelled.- scale
"none"(default, effect units) or"max_abs"(each factor divided by its largest absolute effect, display only).
Value
A ggplot object; $data holds feature, factor, estimate, rank
and label, with display and basis metadata attributes.
Details
Origin: NEW_QOL / none. Credits MOFA2 ranked-weight display workflow; use factor_provenance("plot_factor_weights") 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_weights (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_weights(view, factors = c("F1", "F2"), n_label = 4)