plotRtmsSpectrum {rtms}R Documentation

Plot an RTMS spectrum object

Description

plotRtmsSpectrum() takes an RTMS spectrum object and produces a ggplot object depicting the spectrum

Usage

plotRtmsSpectrum(spectrum, limits = NULL)

Arguments

spectrum

An object of class rtmsSpectrum.

limits

An optional parameter to control the bounds of the m/z x axis. If set to NULL, the default, the full spectrum will be plotted. Otherwise, limits should be a two element numeric vector; if one element is NA, then only the other boundary will be enforced on the x-axis.

Details

Unlike a sample object, an RTMS spectrum is actually quite simple; just a vector of m/z values and vector of intensities. Ordinarily, this could be done using standard ggplot2 functions, such as geom_line. However, mass spectra can often be quite large (on the order of millions of measurements), and sending all that data to be plotted can be computationally intractable. plotRtmsSpectrum() therefore selects a subset of up to 10000 m/z-intensity pairs from the original spectrum to produce a representative plot without rendering millions of points. Any points that are sufficiently larger than their local surroundings (including all relevant peaks) will be included in this subset, as well as a random sampling of points closer to the baseline. This ensures that the peaks plotted will always be present. However, there will be slight differences from one plot to the next in terms of baseline points plotted. This can be eliminated by fixing the random seed using set.seed before plotting.

We also strongly discourage using xlim or seetting the x-coordinate boundaries using standard ggplot2 methods, as these will only be applied after the data has been down-sampled. If you would like to plot a particular subset of the spectrum, it is recommended that you use the limits parameter of this function instead.

Value

A ggplot object depicting the RTMS spectrum.

Examples

plot1 <- plotRtmsSpectrum(exampleSpectrum)
plot2 <- plotRtmsSpectrum(exampleSpectrum,limits=c(1500,1550)) +
				ggplot2::geom_vline(xintercept=c(1516.83,1530.84),
									colour="red",linetype=2)

[Package rtms version 0.2.0 Index]