PlotSpec: Plot Mass Spectrum.

View source: R/PlotSpec.R

PlotSpecR Documentation

Plot Mass Spectrum.

Description

PlotSpec will read, evaluate and plot a deconvoluted mass spectrum (mass*intensity pairs) from TMS-derivatized GC-APCI-MS data. The main purpose is to visualize the relation between deconvoluted masses.

Usage

PlotSpec(
  x = NULL,
  masslab = 0.1,
  rellab = FALSE,
  cutoff = 0.01,
  cols = NULL,
  txt = NULL,
  mz_prec = 4,
  ionization = NULL,
  neutral_losses = NULL,
  neutral_loss_cutoff = NULL,
  substitutions = NULL,
  precursor = NULL,
  xlim = NULL,
  ylim = NULL,
  mar = c(2, 2, 0.5, 0) + 0.5
)

Arguments

x

A two-column matrix with ("mz", "int") information.

masslab

The cutoff value (relative to basepeak) for text annotation of peaks.

rellab

TRUE/FALSE. Label masses relative to largest mass in plot (if TRUE), absolute (if FALSE) or to specified mass (if numeric).

cutoff

Show only peaks with intensity higher than cutoff*I(base peak). This will limit the x-axis accordingly.

cols

Color vector for peaks with length(cols)==nrow(x).

txt

Label peaks with specified text (column 1 specifies x-axis value, column 2 specifies label). Labels will be converted to expressions following the ruleset to format chemical formulas (see Examples).

mz_prec

Numeric precision of m/z (=number of digits to plot).

ionization

Either APCI or ESI (important for main peak determination).

neutral_losses

Data frame of defined building blocks (Name, Formula, Mass). If not provided data("neutral_losses") will be used.

neutral_loss_cutoff

Specifies the allowed deviation in mDa for neutral losses to be accepted from the provided neutral loss list.

substitutions

May provide a two column table of potential substitutions (for adducts in ESI-MS).

precursor

Internally main peaks will be determined up to a supposed precursor obtained by 'DetermineIsomainPeaks' and annotations will only be plotted up to this mass. To plot annotations for the full mass range, set 'precursor' to a higher mass.

xlim

To specify xlim explicitly (for comparative plotting).

ylim

To specify ylim explicitly (for comparative plotting).

mar

Set to NULL to allow specifying margins outside the function (important for use in Shiny App context with brush event).

Value

An annotated plot of the mass spectrum.

Examples

# load APCI test data and apply function
utils::data(apci_spectrum, package = "InterpretMSSpectrum")
PlotSpec(x=apci_spectrum, ionization="APCI")

# normalize test data by intensity
s <- apci_spectrum
s[,2] <- s[,2]/max(s[,2])
PlotSpec(x=s)

# use relative labelling
PlotSpec(x=s, rellab=s[which.max(s[,2]),1])

# avoid annotation of masses and fragments
PlotSpec(x=s, masslab=NULL, neutral_losses=NA)

# provide individual neutral loss set
tmp <- data.frame("Name"=c("Loss1","C2H6"),"Formula"=c("",""),"Mass"=c(90.05,27.995))
PlotSpec(x=s, neutral_losses=tmp)

# provide additional color and annotation information per peak
PlotSpec(x=s, cols=1+(s[,2]>0.1), txt=data.frame("x"=s[s[,2]>0.1,1],"txt"="txt"))

# annotate a sum formula
PlotSpec(x=s, txt=data.frame("x"=s[which.max(s[,2]),1],"txt"="C6H12O6"))

# or annotate a mix of sum formula and text
txt <- data.frame(
 "x" = s[order(s[,2],decreasing=TRUE)[1:3],1],
 "txt" = c("C6H12O6", "some text", "H2SO3")
)
PlotSpec(x=s, txt=txt)

# if 'txt' contains a column SMILES with valid SMILES codes, they will be rendered additionally
txt[,"SMILES"] <- c("O=CC(O)C(O)C(O)C(O)CO", "", "OS(=O)(=O)")
PlotSpec(x=s, txt=txt)
txt[,"w"] <- rep(0.4,3)
PlotSpec(x=s, txt=txt)

# simulate a Sodium adduct to the spectrum (and annotate using substitutions)
p <- which.max(s[,2])
s <- rbind(s, c(21.98194+s[p,1], 0.6*s[p,2]))
PlotSpec(x=s, substitutions=matrix(c("H","Na"),ncol=2,byrow=TRUE))

# add structural formulas by providing SMILES codes

# use predefined ESI parameter set
PlotSpec(x=s, ionization="ESI")

InterpretMSSpectrum documentation built on April 10, 2026, 5:07 p.m.