qplot.electrophoresis: Plot electrophoresis data

View source: R/ggplot.R

qplot.electrophoresisR Documentation

Plot electrophoresis data

Description

This function is a shortcut to plot the data from an electrophoresis object, wrapping ggplot similarly to qplot. The result is analogous to electropherograms produced by the Agilent software.

Usage

qplot.electrophoresis(
  electrophoresis,
  x = "length",
  y = "molarity",
  ...,
  log = "",
  normalize = c("none", "total", "window"),
  facets = ~sample.index,
  margins = FALSE,
  scales = "fixed",
  geom = c("line", "area"),
  include.ladder = FALSE,
  include.markers = FALSE,
  lower.marker.spread = 10,
  xlim = c(NA, NA),
  ylim = c(NA, NA),
  show.peaks = c("all", "markers", "none"),
  region.alpha = 0.2,
  area.alpha = 0.2,
  title = NULL,
  xlab = NULL,
  ylab = NULL
)

Arguments

electrophoresis

An electrophoresis object.

x

The name of the variable to use as the x-value of each point in the graph as a character vector. Usually one of "time", "aligned.time", "distance", "relative.distance", or "length".

y

The name of the variable to use as the y-value of each point in the graph, as a character vector. Usually one of "fluorescence", "concentration", or "molarity".

...

Additional aesthetics passed to the geom for the main data (not the peaks or regions). Unlike the previous variables that are specified by character vectors, these use the normal aesthetic syntax, e.g. color = sample.name.

log

Which variables to log-transform ("x", "y", or "xy").

normalize

Normalize the y-values in each sample with normalize.proportion. "total" normalizes by the entire sample (between markers), or "window" normalizes only within the x-limits of the plot specified by xlim. "none" doesn't normalize.

facets

Faceting formula to use. Picks facet_wrap or facet_grid depending on whether the formula is one- or two-sided. If NULL, overlay all samples in one color-coded graph.

margins

Display marginal facets (via facet_grid) if using a two-side faceting formula.

scales

Scaling rules for the facets, passed to facet_wrap.

geom

Name of the geom to draw. Only "line" (geom_line, to get continuous curves) and "area" (geom_area, to fill the area under the curves) are supported.

include.ladder

If FALSE, graph only the actual samples and not the ladder well(s).

include.markers

If FALSE, graph only data between the marker peaks.

lower.marker.spread

If normalizing the totals or excluding marker peaks, extend the lower marker peak by this amount (via between.markers).

xlim, ylim

Limits of x- and y-axes

show.peaks

Whether to fill the areas under reported peaks. "all": fill all peaks. "markers": fill only the marker peak(s). "none": don't fill any peaks.

region.alpha

Alpha-transparency of the highlight in the reported regions of interested. Set to NA to skip plotting the regions.

area.alpha

Alpha-transparency of the filled areas under the curves, if geom = "area", to make them visible through one another.

title, xlab, ylab

Plot title, x-axis label, and y-axis label.

Value

A ggplot object containing several layers. You can draw it directly or customize it like any other ggplot object by adding more layers.

Variable transformation

Before plotting, unless the y-variable is fluorescence, it is scaled by the differentials in the x-value. Thus the units of the y-axis are divided by the units of the x-axis, e.g. molarity per length. This ensures that the area under the curve (width times height) represents the desired variable in the correct units. For example, if the x-variable is length in bp, the graph will be equivalent to a histogram with one bar for each possible molecule length in base pairs.

Geoms and aesthetics

The x- and y-variable names must be provided as character objects, e.g. "length" rather than length. However, additional aesthetics in ... are passed directly to aes so they must be provided as the variable names themselves, e.g. color = sample.observations rather than color = "sample.observations".

Both of the supported geoms for the main data, geom_line and geom_area, are given the specified x-variable as x and the appropriately transformed y-variable as y, as well as group = sample.index to ensure overlaid samples are plotted distinctly. If facets is null, then the geom is also given either color = sample.name (if geom == "line") or fill = sample.name (if geom == "area") to color-code overlaid samples. Thus if replicates of the same sample have the same name, they will also have the same color.

If peak.fill is not NA and facets is not null and electrophoresis$peaks is not null, then the plot gets an extra geom_area from only the subset of electrophoresis$data that is within the reported peaks, using the same settings as above except fill = peak.fill. If you use a faceting formula other than NULL that allows some samples to be overlaid in the same facet, it may be a good idea to set peak.fill = NA so their peaks don't overlap.

If region.alpha is not NA and facets is not null and electrophoresis$regions is not null, then the plot gets a geom_rect with ymin = -Inf, ymax = Inf and xmin and xmax set to the lower and upper boundaries of the regions, while alpha = region.alpha.

See Also

rawplot.electrophoresis, sparkline.electrophoresis, violin.electrophoresis


jwfoley/bioanalyzeR documentation built on Aug. 1, 2023, 4:46 a.m.