spatial_plot: Spatially Plot MSI Data

Description Usage Arguments Details Value See Also Examples

View source: R/plot.R

Description

Produces a spatial plot of the given MSI data, designed to be used with combine_peaklists and associated load_* functions. Usually would be used on a subset of the Peak-list produced by combine_peaklist, those near a particular mass for example, see example below for an example of this example.

Usage

1
2
spatial_plot(df.peak, df.spec, plot.var = "intensity", id.var = "Acq",
  x.var = "X", y.var = "Y", return.plot = FALSE, print.plot = TRUE)

Arguments

df.peak

A Peak-list data.frame as produced by combine_peaklists, or more commonly a subset thereof.

df.spec

A Spectra-list data.frame as produced by combine_peaklists.

plot.var

A string matching the variable name in df.peak to be plotted.

id.var

A string matching the variable name that uniquely identifies spectra in both df.peak and df.spec, thereby linking that information between them.

x.var

A string matching the variable name in df.spec that contains the X-coordinates of the spectra.

y.var

A string matching the variable name in df.spec that contains the Y-coordinates of the spectra.

return.plot

A logical value that if TRUE will cause spatial_plot to return a ggplot object and if FALSE will instead return the data.frame underlying it.

print.plot

A logical value indicating whether the plot should be printed to the current graphics device.

Details

Note spatial_plot assumes that there are no occurrences of multiple peaks from the same spectrum in the input peak-list df.peak. Any such occurrences should be dealt with before calling spatial_plot, as otherwise it will throw an error.

Value

On successful completion returns either a ggplot object or the data.frame used to produce said ggplot object, depending on the value of return.plot.

If return.plot is FALSE, the returned data.frame will contain rows that represent unique X-Y coordinate pairs in a rectanglular region extending from the minimum X-coordinate in df.spec minus one to the maximum plus one (inclusive), and similarly from the minimum Y-coordinate in df.spec minus one to the maximum plus one (inclusive), and for each such unique X-Y coordinate pair four columns represent the relevant plotting information:

If return.plot is TRUE, the returned ggplot object is a geom_tile plot with axes labelled with x.var and y.var respectively, a legend for plot.var, X-Y coordinate pairs (or pixels) for which no spectrum was acquired blank, and X-Y coordinate pairs (or pixels) for which a spectrum was acquired but no peaks are present in df.peak in darkened grey. The plot uses coord_fixed() to match X and Y scales.

See Also

Intended to be used with combine_peaklists, associated load_* functions, and the ggplot2 package (https://cran.r-project.org/web/packages/ggplot2/index.html), hadley's book on ggplot2 is a good resource, see his github (https://github.com/hadley/ggplot2-book) or you can access samples and/ or buy his book from the website (http://ggplot2.org/book).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
i.path = system.file("extdata", "test1", package = "dipps")
n.empty = combine_peaklists(i.path)
o.name = basename(i.path)
df.spec = load_speclist(o.name)
df.peak = load_peaklist(o.name)

# Select a m/z window of interest, in this case m/z = 1570.677 +/- 0.1 Da
df.cal = subset(df.peak, abs(m.z - 1570.677) < 0.1)

# Plot log-intensity of said m/z window.
df.cal$log.intensity = log1p(df.cal$intensity)
p = spatial_plot(df.cal, df.spec, plot.var = "log.intensity")

Armadilloa16/dipps documentation built on May 5, 2019, 7:06 a.m.