knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.width = 8, fig.height = 6 )
Density plots display the distribution of meta-data values corresponding to peaks observed in one or more samples, a group, or pair of groups. The densityPlot
function can display histograms or smoothed density, and it can display both together if plotting a single distribution (i.e. one sample or one aggregated group). The distribution of any numeric column of the e_meta
element may be plotted.
To construct a density plot for a single sample, first construct a subset containing only the sample of interest. By default, densityPlot
plots the distribution (without a histogram) of the chosen variable.
library(ftmsRanalysis) data("exampleProcessedPeakData") one_sample <- subset(exampleProcessedPeakData, samples="EM0011_sample") densityPlot(one_sample, variable="NOSC")
Setting the plot_hist
parameter to TRUE
will display both the curve and histogram.
densityPlot(one_sample, variable="NOSC", plot_hist=TRUE)
Alternatively, using plot_curve=FALSE
gives just a histogram. The yaxis
parameter controls the scale of the y-axis: it can be either "density" (default) or "count"
densityPlot(one_sample, variable="NOSC", plot_hist=TRUE, plot_curve=FALSE, yaxis="count")
The densityPlot
function can also choose a single sample from a larger dataset, using the samples
parameter:
densityPlot(exampleProcessedPeakData, variable="NOSC", samples="EM0069_sample")
The samples
parameter may also be used to specify more than one sample, although only curves may be plotted, not histograms.
densityPlot(exampleProcessedPeakData, variable="NOSC", samples=c("EM0011_sample", "EM0013_sample", "EM0015_sample"), curve_colors=c("blue", "red", "green"))
Since the exampleProcessedPeakData
object has a group definition (see group_designation
for how to construct this), the groups
parameter can be used to select multiple groups to plot (these curves are the distribution combining all peaks observed by samples in the group).
getGroupDF(exampleProcessedPeakData) densityPlot(exampleProcessedPeakData, variable="NOSC", samples=FALSE, groups=c("M_C", "M_S"))
The samples
and groups
parameters work in similar ways to select multiple distributions to plot. An NA
value indicates that all samples or groups in the data object should be plotted, a FALSE
value suppresses curves, and a character vector may be used to select specific samples and/or groups. The samples
parameter is NA
by default (so it will plot all samples found) and groups
is FALSE
by default (do not plot groups).
The easiest way to plot all samples in a group, and the group aggregate is to subset down by group, then call densityPlot
. (Recall that all samples are plotted by default so only the groups
parameter must be specified.)
MSgroup <- subset(exampleProcessedPeakData, groups="M_S") densityPlot(MSgroup, variable="NOSC", groups=NA)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.