Skip to contents

Choose a preview to get its plotting recipe. All plots use one simulated fit.

Native flashier · flashier.utils · Shared setup · Credits

Native flashier

Native mean displays use per-component maximum-absolute scaling. The scree plot shows native PVE.

flashier.utils

Activity and effect displays keep the declared coordinates. Only the structure recipe requests row-sum normalization.

Shared setup

Run this setup once before a recipe. It uses 24 samples and 12 features. Samples occupy rows. Nonnegative activity pairs with signed feature effects. The group and covariate are artificial; no biological result follows.

library(flashier.utils)
set.seed(17)
activity_truth <- cbind(
  c(rep(3, 12), rep(0.3, 12)),
  c(rep(0.3, 12), rep(3, 12))
) + matrix(runif(48, 0, 0.4), 24, 2)
effect_truth <- cbind(
  c(2, 1.7, 1.4, 1.1, -0.6, -1.2, rep(0.1, 6)),
  c(rep(-0.15, 6), 2, 1.7, 1.4, 1.1, -0.8, -1.2)
)
X <- tcrossprod(activity_truth, effect_truth) +
  matrix(rnorm(288, sd = 0.1), 24, 12)
dimnames(X) <- list(sprintf("s%02d", 1:24), sprintf("g%02d", 1:12))
fit <- flashier::flash(
  X, S = 0.1, var_type = NULL, greedy_Kmax = 2,
  ebnm_fn = list(ebnm::ebnm_point_exponential, ebnm::ebnm_normal),
  nullcheck = FALSE, backfit = TRUE, verbose = 0
)
view <- standardize_factors(
  fit, sample_side = "rows", scaling = "raw",
  prior_support = c(activity = "nonnegative", effects = "signed"),
  feature_scale = "simulated_intensity"
)
metadata <- data.frame(
  sample = rownames(X), group = rep(c("A", "B", "C"), each = 8)
)
groups <- setNames(metadata$group, metadata$sample)
covariate <- setNames(seq(0, 1, length.out = nrow(X)), rownames(X))

scaling = "raw" keeps the native posterior-mean coordinates. Each recipe reuses fit, view, metadata, groups and covariate without refitting or changing their values.

Plotting recipes

Factor variance

Native PVE uses the fitted matrix. Nonorthogonal factors do not give an additive PCA variance partition.

native_scree <- flashier::flash_plot_scree(fit, labels = TRUE)
native_scree

Function reference: flash_plot_scree(). Shared setup.

Native heatmap

For sample rows, pm_which = "loadings" selects samples. Native mean displays divide each component by its maximum absolute mean.

native_heatmap <- flashier::flash_plot_heatmap(
  fit, pm_which = "loadings", pm_groups = groups
)
native_heatmap

Function reference: flash_plot_heatmap(). Shared setup.

Native bars

Each bar is one sample. Values are maximum-absolute-scaled posterior means, not raw activity or probabilities.

native_bar <- flashier::flash_plot_bar(
  fit, pm_which = "loadings", pm_groups = groups
)
native_bar

Function reference: flash_plot_bar(). Shared setup.

Native histogram

The bins summarize maximum-scaled posterior means. Group colors identify distributions; overlapping bins can hide one group.

native_histogram <- flashier::flash_plot_histogram(
  fit, pm_which = "loadings", pm_groups = groups, bins = 8
)
native_histogram

Function reference: flash_plot_histogram(). Shared setup.

Native scatter

The covariate is artificial and aligned to sample rows before plotting. The x-axis shows maximum-scaled posterior means; the y-axis shows that covariate. This display is descriptive.

native_scatter <- flashier::flash_plot_scatter(
  fit, pm_which = "loadings", pm_groups = groups,
  covariate = unname(covariate[rownames(X)])
)
native_scatter

Function reference: flash_plot_scatter(). Shared setup.

Native structure

Stacks use per-component maximum-absolute scaling. Their row totals need not equal one. Use nonnegative loadings; signed effects belong in a heatmap.

native_structure <- flashier::flash_plot_structure(
  fit, pm_which = "loadings", pm_groups = groups
) + ggplot2::labs(colour = NULL)
native_structure

Function reference: flash_plot_structure(). Shared setup.

Activity heatmap

Colors show raw activity coordinates. No display normalization changes their values. Group labels describe simulated samples.

activity_heatmap <- plot_factor_activity(
  view, metadata = metadata, group = "group", style = "heatmap"
)
activity_heatmap

Function reference: plot_factor_activity(). Shared setup.

Activity points

Each point is one simulated sample in raw activity coordinates. Overlapping points can hide samples; the example supplies no biological replication.

activity_point <- plot_factor_activity(
  view, metadata = metadata, group = "group", style = "point"
)
activity_point

Function reference: plot_factor_activity(). Shared setup.

Activity boxplots

style = "distribution" draws boxplots. Values retain raw activity units. The boxes do not show posterior uncertainty or a density estimate.

activity_distribution <- plot_factor_activity(
  view, metadata = metadata, group = "group", style = "distribution"
)
activity_distribution

Function reference: plot_factor_activity(). Shared setup.

Activity structure

Nonnegative activities are divided by each sample’s activity sum for display. This differs from native maximum-scaled stacks. Zero-sum samples are omitted. The plot records their IDs under zero_activity_samples in its analysis_metadata attribute. The checked example has none. Raw coordinates stay unchanged.

activity_structure <- plot_factor_activity(
  view, metadata = metadata, group = "group", style = "structure",
  display_normalization = "row_sum"
) + ggplot2::theme(
  axis.text.x = ggplot2::element_text(angle = 90, hjust = 1, size = 7)
)
activity_structure

Function reference: plot_factor_activity(). Shared setup.

Feature heatmap

Colors show selected signed feature effects in the declared factor basis. With raw activity, matched effects reconstruct simulated intensity. No maximum scaling is applied.

feature_heatmap <- plot_factor_features(
  view, factors = colnames(view$effects), n = 4, style = "heatmap"
)
feature_heatmap

Function reference: plot_factor_features(). Shared setup.

Feature bars

Bars retain signed feature effects and a zero baseline. Selection uses the largest absolute effects per factor. Factor signs alone do not establish activation or repression.

feature_bar <- plot_factor_features(
  view, factors = colnames(view$effects), n = 4, style = "bar", transpose = TRUE
)
feature_bar

Function reference: plot_factor_features(). Shared setup.

Ranked weights

All features are ranked by signed effect within each factor; the labelled points are the largest absolute effects. Effects keep the declared coordinates. A label is a ranking, not a biological call.

feature_weights <- plot_factor_weights(
  view, factors = colnames(view$effects), n_label = 4
)
feature_weights

Function reference: plot_factor_weights(). Shared setup.

Factor scatter

Each point is one sample; axes are raw activity on two factors. Colour comes from the metadata column named in color. Co-occurrence across samples is descriptive.

activity_scatter <- plot_factor_scatter(
  view, factors = colnames(view$activity)[1:2], metadata = metadata, color = "group"
)
activity_scatter

Function reference: plot_factor_scatter(). Shared setup.

PVE bars

Native PVE per factor as bars. Nonorthogonal factors do not partition variance additively, so bars need not sum to the total.

factor_pve_plot <- plot_factor_pve(fit)
factor_pve_plot

Function reference: plot_factor_pve(). Shared setup.

Data heatmap

Observed values of the strongest F1 features, one column per sample ordered by F1 activity, split by group. Each feature is z-scored for display only; pass scale = "none" for supplied units.

data_heatmap <- plot_factor_data(
  view, X, factor = "F1", n = 6, metadata = metadata, group = "group"
)
data_heatmap

Function reference: plot_factor_data(). Shared setup.

Embedding

Any named samples by two coordinate matrix works; here classical MDS of the activity matrix. Colour is raw activity per factor. Geometry is exploratory and is not batch correction or replication.

embedding <- stats::cmdscale(stats::dist(view$activity), k = 2)
activity_embedding <- plot_factor_embedding(
  view, embedding, factors = colnames(view$activity)
)
activity_embedding

Function reference: plot_factor_embedding(). Shared setup.

Next tasks

Get started explains native fitting and extraction. Advanced use covers units, uncertainty and membership filtering. Compare priors separates prediction from program recovery. Pancreas programs shows a real-data case study.

Credits

Native FLASH/flashier: Jason Willwerscheid, Peter Carbonetto, Wei Wang and Matthew Stephens. EBNM: Jason Willwerscheid, Matthew Stephens and Peter Carbonetto. Feature selection adapts singlecelljamboreeR helpers by Peter Carbonetto and Matthew Stephens. Activity and feature display workflows credit David Zemmour and the Zemmour Lab. These recipes call public APIs; no upstream source is copied. Plot styling uses ggplot2 by Hadley Wickham, Thomas Lin Pedersen and the contributors listed in the full credits. Use citation("ggplot2") for its method. Use citation("flashier"), citation("ebnm") and factor_provenance() for methods and runtime records. See full credits and licenses.

The R Graph Gallery density page inspired the library sections and preview-to-recipe navigation. All figures and recipes here are original; no page assets or prose are copied. plot(fit, plot_type = ...) dispatches to the native plotters above; those aliases do not need duplicate examples.