| trans_rarefy | R Documentation |
Rarefaction based on the trans_norm class and visualization of the rarefaction curve based on the ggplot2.
new()trans_rarefy$new( dataset = NULL, alphadiv = "Shannon", depth = NULL, PD = FALSE, ... )
datasetthe object of microtable Class.
alphadivdefault "Shannon"; one or more alpha diversity measurements used for the rarefaction; see microtable$cal_alphadiv for all the available measurements. The measurement names are case-insensitive, e.g. "shannon" is same as "Shannon". Multiple measurements are supported and share the same rarefying process.
depthdefault NULL; a numeric vector used for the rarefying. 0 represents using the original data without rarefying and the diversity values are all set to 0 as the starting point of the curve.
If NULL, a sequence of 10 depths from 0 to the maximum of sample sums (i.e. max(dataset$sample_sums())) is generated automatically using a quadratic spacing round(max_depth * seq(0, 1, length.out = 10)^2),
so the depths are denser in the low-depth region where the rarefaction curve rises steeply and sparser in the high-depth region where the curve becomes flat.
Note that for each sample, only the depths not larger than its own sequencing depth are available,
as the sample is removed at the larger depths by the norm function of trans_norm class, leading to an interrupted curve in the plot.
PDdefault FALSE; whether add Faith's phylogenetic diversity (PD) to the alpha diversity. The calculation depends on cal_alphadiv function of microtable class,
so the phylogenetic tree (phylo_tree in the dataset) is necessary for this option.
...parameters passed to norm function of trans_norm class, such as method ("rarefy" or "SRS") and rngseed,
except the sample.size parameter which is controlled by the depth parameter.
res_rarefy stored in the object, which is a data.frame with the columns SampleID (sample name),
seqnum (the rarefying depth) and the alpha diversity measurements used (the column names are the standard measurement names).
The measurements used are also stored in object$measure, and the rarefying depths in object$depth.
\dontrun{
data(dataset)
t1 <- trans_rarefy$new(dataset = dataset, depth = c(0, 10, 50, 400, 800))
# the depth is generated automatically when it is not provided
t1 <- trans_rarefy$new(dataset = dataset)
}
plot_rarefy()Plotting the rarefied result.
trans_rarefy$plot_rarefy( color_values = RColorBrewer::brewer.pal(8, "Dark2"), color = "SampleID", measure = NULL, show_point = TRUE, point_size = 0.3, point_alpha = 0.6, add_fitting = FALSE, fitting_method = "lm", fitting_formula = y ~ log(x + 1), x_axis_title = "Sequence number", y_axis_title = NULL, show_legend = TRUE, show_samplename = FALSE, samplename_size = 3, samplename_color = "grey30", ... )
color_valuescolors used for presentation.
colordefault "SampleID"; color mapping in the plot.
measuredefault NULL; the alpha diversity measurement(s) used as the y axis; see the alphadiv parameter in new function.
If NULL, all the measures stored in the object are used. When multiple measures are used, the plot is faceted by the measures.
show_pointdefault TRUE; whether show the point.
point_sizedefault .3; point size value.
point_alphadefault .6; point alpha value.
add_fittingdefault FALSE; whether add fitted line.
fitting_methoddefault "lm"; the method used by ggplot2::geom_smooth function. Only available when add_fitting = TRUE.
The default "lm" avoids the warnings generated by the default "loess" method, as there are usually only a few depths for each sample.
fitting_formuladefault y ~ log(x + 1); the formula used by ggplot2::geom_smooth function. Only available when add_fitting = TRUE.
Note that x + 1 is used instead of x, as the depth 0 makes log(x) invalid.
x_axis_titledefault "Sequence number"; x axis title.
y_axis_titledefault NULL; default NULL represents the measure used; when multiple measures are used, default NULL represents "Value".
show_legenddefault TRUE; whether show the legend in the plot.
show_samplenamedefault FALSE; whether show the sample name in the plot.
samplename_sizedefault 3; the sample name text size. Only available when show_samplename is TRUE.
samplename_colordefault "grey30"; sample name text color. Only available when show_samplename is TRUE.
...parameters pass to ggplot2::geom_line (when add_fitting = FALSE) or ggplot2::geom_smooth (when add_fitting = TRUE).
ggplot.
\dontrun{
t1$plot_rarefy(color = "Group")
}
print()Print the trans_rarefy object.
trans_rarefy$print()
clone()The objects of this class are cloneable with this method.
trans_rarefy$clone(deep = FALSE)
deepWhether to make a deep clone.
## ------------------------------------------------
## Method `trans_rarefy$new`
## ------------------------------------------------
## Not run:
data(dataset)
t1 <- trans_rarefy$new(dataset = dataset, depth = c(0, 10, 50, 400, 800))
# the depth is generated automatically when it is not provided
t1 <- trans_rarefy$new(dataset = dataset)
## End(Not run)
## ------------------------------------------------
## Method `trans_rarefy$plot_rarefy`
## ------------------------------------------------
## Not run:
t1$plot_rarefy(color = "Group")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.