plot_density: Density Plots by Sample

View source: R/plot_density.R

plot_densityR Documentation

Density Plots by Sample

Description

This function displays each sample's omic data distribution as a density curve.

Usage

plot_density(
  dat,
  group = NULL,
  pal_group = "npg",
  xlab = NULL,
  title = "Density Plot",
  legend = "right",
  hover = FALSE
)

Arguments

dat

Omic data matrix or matrix-like object with rows corresponding to probes and columns to samples. Raw counts stored in DGEList or DESeqDataSet objects are automatically extracted and transformed to the log2-CPM scale, with a warning.

group

Optional character or factor vector of length equal to sample size. Numeric or logical vectors are silently coerced to factor. Levels are used to color density curves. If supplied, legend title defaults to "Group". Override this feature by passing a named list instead.

pal_group

String specifying the color palette to use if group is non-NULL, or a vector of such strings with length equal to the number of vectors passed to group. Options include "ggplot", all qualitative color schemes available in RColorBrewer, and the complete collection of ggsci palettes. Alternatively, a character vector of colors with length equal to the cumulative number of levels in group.

xlab

Optional label for x-axis.

title

Optional plot title.

legend

Legend position. Must be one of "bottom", "left", "top", "right", "bottomright", "bottomleft", "topleft", or "topright".

hover

Show sample name by hovering mouse over data point? If TRUE, the plot is rendered in HTML and will either open in your browser's graphic display or appear in the RStudio viewer.

Details

Density curves offer an intuitive way to visualize an omic data distribution. They are common in quality control pipelines, and may be especially helpful when contrasting pre- and post-normalization matrices. plot_density can additionally be used to inspect for batch effects or associations with phenotypic factors by using the group argument.

See Also

plotDensities

Examples

# Density plots by sample
mat <- matrix(rnorm(500 * 10), nrow = 500, ncol = 10)
plot_density(mat)

# Density plots by group
grp <- rep(c("A", "B"), each = 5)
plot_density(mat, group = grp)


dswatson/bioplotr documentation built on March 3, 2023, 9:43 p.m.