Skip to contents

Draws one sub-plot per cluster of a scaled expression matrix (e.g. as produced by run_clustering), combined with plotly::subplot(). Three display modes are available: individual sample lines, a mean/median line with error bars, or a mean/median line with a shaded error band. Summary statistics (mean, median and their spreads) are derived internally with summary_se.

Usage

interactive_cluster_profiles(
  matrices_by_cluster,
  cluster_display = c("filled_line", "sample_lines", "error_bars"),
  average_type = c("mean", "median"),
  limits = c("sd", "se", "ci"),
  colors = NULL,
  sample_order = NULL,
  max_sample_lines = 100,
  summarised_matrices_by_cluster = NULL
)

Arguments

matrices_by_cluster

A named list of matrices/data frames, one per cluster, features by row and samples by column (e.g. the input matrix split by clustering$clustering from run_clustering). Names should be the cluster numbers as produced by split(), since colors is indexed by cluster number.

cluster_display

'filled_line' (a mean/median line with a shaded error band), 'sample_lines' (individual sample profiles) or 'error_bars' (a mean/median line with error bars)

average_type

'mean' or 'median'

limits

Which spread to show around the average: 'sd' (standard deviation), 'se' (standard error) or 'ci' (95% confidence interval). Ignored when cluster_display = "sample_lines"

colors

A vector of colors, indexed by cluster number (i.e. colors[[2]] colors the cluster named "2" in matrices_by_cluster). Defaults to make_color_scale

sample_order

Character vector giving the sample (x axis) display order. Defaults to colnames() of the first cluster's matrix

max_sample_lines

Maximum number of sample lines drawn per cluster under cluster_display = "sample_lines"; larger clusters are randomly subsampled to this many rows

summarised_matrices_by_cluster

Precomputed summary statistics, one element per cluster, as returned by summary_se on each element of matrices_by_cluster. Computed internally if not supplied; callers that already have this (e.g. to cache it separately from the display controls below) can pass it through directly

Value

output A plotly htmlwidget

Examples

set.seed(1)
matrices_by_cluster <- list(
  `1` = matrix(rnorm(30), nrow = 5, dimnames = list(paste0("gene", 1:5), paste0("sample", 1:6))),
  `2` = matrix(rnorm(30), nrow = 5, dimnames = list(paste0("gene", 6:10), paste0("sample", 1:6)))
)

interactive_cluster_profiles(matrices_by_cluster, cluster_display = "filled_line")