| trans_beta {microeco} | R Documentation |
Create trans_beta object for beta-diversity analysis
Description
This class is a wrapper for a series of beta-diversity related analysis,
including ordination analysis based on An et al. (2019) <doi:10.1016/j.geoderma.2018.09.035>, group distance comparision,
clustering, perMANOVA based on Anderson al. (2008) <doi:10.1111/j.1442-9993.2001.01070.pp.x>, ANOSIM and PERMDISP.
Note that the beta diversity analysis methods related with environmental variables are encapsulated within the trans_env class.
Methods
Public methods
Method new()
Usage
trans_beta$new(dataset = NULL, measure = NULL, group = NULL)
Arguments
datasetthe object of
microtableclass.measuredefault NULL; a matrix name stored in
microtable$beta_diversitylist, such as "bray" or "jaccard", or a customized matrix; used for ordination, manova, group distance comparision, etc.; Please seecal_betadivfunction ofmicrotableclass for more details.groupdefault NULL; sample group used for manova, betadisper or group distance comparision.
Returns
measure, group and dataset stored in the object.
Examples
data(dataset) t1 <- trans_beta$new(dataset = dataset, measure = "bray", group = "Group")
Method cal_ordination()
Unconstrained ordination.
Usage
trans_beta$cal_ordination( method = "PCoA", ncomp = 3, trans = FALSE, scale_species = FALSE, scale_species_ratio = 0.8, ... )
Arguments
methoddefault "PCoA"; "PCA", "DCA", "PCoA" or "NMDS". PCA: principal component analysis; DCA: detrended correspondence analysis; PCoA: principal coordinates analysis; NMDS: non-metric multidimensional scaling. Please refer to the paper <doi:10.1111/j.1574-6941.2007.00375.x> for the details of the methods.
ncompdefault 3; dimensions shown in the results (except method "NMDS").
transdefault FALSE; whether species abundance will be square transformed; only available when
methodis "PCA" or "DCA".scale_speciesdefault FALSE; whether species loading in PCA or DCA is scaled.
scale_species_ratiodefault 0.8; the ratio to scale up the loading; multiply by the maximum distance between samples and origin. Only available when
scale_species = TURE....parameters passed to
vegan::rdafunction whenmethod = "PCA", orvegan::decoranafunction whenmethod = "DCA", orape::pcoafunction whenmethod = "PCoA", orvegan::metaMDSfunction when whenmethod = "NMDS".
Returns
res_ordination stored in the object.
Examples
t1$cal_ordination(method = "PCoA")
Method plot_ordination()
Plot the ordination result.
Usage
trans_beta$plot_ordination( plot_type = "point", color_values = RColorBrewer::brewer.pal(8, "Dark2"), shape_values = c(16, 17, 7, 8, 15, 18, 11, 10, 12, 13, 9, 3, 4, 0, 1, 2, 14), plot_color = NULL, plot_shape = NULL, plot_group_order = NULL, add_sample_label = NULL, point_size = 3, point_alpha = 0.8, centroid_segment_alpha = 0.6, centroid_segment_size = 1, centroid_segment_linetype = 3, ellipse_chull_fill = TRUE, ellipse_chull_alpha = 0.1, ellipse_level = 0.9, ellipse_type = "t", NMDS_stress_pos = c(1, 1), NMDS_stress_text_prefix = "", loading_arrow = FALSE, loading_taxa_num = 10, loading_text_color = "black", loading_arrow_color = "grey30", loading_text_size = 3, loading_text_italic = FALSE )
Arguments
plot_typedefault "point"; one or more elements of "point", "ellipse", "chull" and "centroid".
- 'point'
add sample points
- 'ellipse'
add confidence ellipse for points of each group
- 'chull'
add convex hull for points of each group
- 'centroid'
add centroid line of each group
color_valuesdefault
RColorBrewer::brewer.pal(8, "Dark2"); colors palette for different groups.shape_valuesdefault c(16, 17, 7, 8, 15, 18, 11, 10, 12, 13, 9, 3, 4, 0, 1, 2, 14); a vector for point shape types of groups, see
ggplot2tutorial.plot_colordefault NULL; a colname of
sample_tableto assign colors to different groups in plot.plot_shapedefault NULL; a colname of
sample_tableto assign shapes to different groups in plot.plot_group_orderdefault NULL; a vector used to order the groups in the legend of plot.
add_sample_labeldefault NULL; a column name in
sample_table; If provided, show the point name in plot.point_sizedefault 3; point size when "point" is in
plot_typeparameter.point_alphadefault .8; point transparency in plot when "point" is in
plot_typeparameter.centroid_segment_alphadefault 0.6; segment transparency in plot when "centroid" is in
plot_typeparameter.centroid_segment_sizedefault 1; segment size in plot when "centroid" is in
plot_typeparameter.centroid_segment_linetypedefault 3; the line type related with centroid in plot when "centroid" is in
plot_typeparameter.ellipse_chull_filldefault TRUE; whether fill colors to the area of ellipse or chull.
ellipse_chull_alphadefault 0.1; color transparency in the ellipse or convex hull depending on whether "ellipse" or "centroid" is in
plot_typeparameter.ellipse_leveldefault .9; confidence level of ellipse when "ellipse" is in
plot_typeparameter.ellipse_typedefault "t"; ellipse type when "ellipse" is in
plot_typeparameter; see type instat_ellipse.NMDS_stress_posdefault c(1, 1); a numerical vector with two values used to represent the insertion position of the stress text. The first one denotes the x-axis, while the second one corresponds to the y-axis. The assigned position is determined by multiplying the respective value with the maximum point on the corresponding coordinate axis. Thus, the x-axis position is equal to
max(points of x axis) * NMDS_stress_pos[1], and the y-axis position is equal tomax(points of y axis) * NMDS_stress_pos[2]. Negative values can also be utilized for the negative part of the axis.NMDS_stress_pos = NULLdenotes no stress text to show.NMDS_stress_text_prefixdefault ""; If NMDS_stress_pos is not NULL, this parameter can be used to add text in front of the stress value.
loading_arrowdefault FALSE; whether show the loading using arrow.
loading_taxa_numdefault 10; the number of taxa used for the loading. Only available when
loading_arrow = TRUE.loading_text_colordefault "black"; the color of taxa text. Only available when
loading_arrow = TRUE.loading_arrow_colordefault "grey30"; the color of taxa arrow. Only available when
loading_arrow = TRUE.loading_text_sizedefault 3; the size of taxa text. Only available when
loading_arrow = TRUE.loading_text_italicdefault FALSE; whether using italic for the taxa text. Only available when
loading_arrow = TRUE.
Returns
ggplot.
Examples
t1$plot_ordination(plot_type = "point")
t1$plot_ordination(plot_color = "Group", plot_shape = "Group", plot_type = "point")
t1$plot_ordination(plot_color = "Group", plot_type = c("point", "ellipse"))
t1$plot_ordination(plot_color = "Group", plot_type = c("point", "centroid"),
centroid_segment_linetype = 1)
Method cal_manova()
Calculate perMANOVA (Permutational Multivariate Analysis of Variance) based on the adonis2 function of vegan package <doi:10.1111/j.1442-9993.2001.01070.pp.x>.
Usage
trans_beta$cal_manova( manova_all = TRUE, manova_set = NULL, group = NULL, by_group = NULL, p_adjust_method = "fdr", ... )
Arguments
manova_alldefault TRUE; TRUE represents test for all the groups, i.e. the overall test; FALSE represents test for all the paired groups.
manova_setdefault NULL; other specified group set for manova, such as
"Group + Type"and"Group*Type". Please also see theformulaparameter (only right-hand side) inadonis2function of vegan package. The parameter manova_set has higher priority than manova_all parameter. If manova_set is provided; manova_all is disabled.groupdefault NULL; a column name of
sample_tableused for manova. If NULL, searchgroupvariable stored in the object. Available whenmanova_setis not provided.by_groupdefault NULL; one column name in
sample_table; used to perform paired comparisions within each group. Only available whenmanova_all = FALSEandmanova_setis not provided.p_adjust_methoddefault "fdr"; p.adjust method; available when
manova_all = FALSE; seemethodparameter ofp.adjustfunction for available options....parameters passed to
adonis2function ofveganpackage.
Returns
res_manova stored in object with data.frame class.
Examples
t1$cal_manova(manova_all = TRUE)
Method cal_anosim()
Analysis of similarities (ANOSIM) based on the anosim function of vegan package.
Usage
trans_beta$cal_anosim( paired = FALSE, group = NULL, by_group = NULL, p_adjust_method = "fdr", ... )
Arguments
paireddefault FALSE; whether perform paired test between any two combined groups from all the input groups.
groupdefault NULL; a column name of
sample_table. If NULL, searchgroupvariable stored in the object.by_groupdefault NULL; one column name in
sample_table; used to perform paired comparisions within each group. Only available whenpaired = TRUE.p_adjust_methoddefault "fdr"; p.adjust method; available when
paired = TRUE; see method parameter ofp.adjustfunction for available options....parameters passed to
anosimfunction ofveganpackage.
Returns
res_anosim stored in object with data.frame class.
Examples
t1$cal_anosim()
Method cal_betadisper()
Multivariate homogeneity test of groups dispersions (PERMDISP) based on betadisper function in vegan package.
Usage
trans_beta$cal_betadisper(...)
Arguments
...parameters passed to
betadisperfunction.
Returns
res_betadisper stored in object.
Examples
t1$cal_betadisper()
Method cal_group_distance()
Convert symmetric distance matrix to distance table of paired samples that are within groups or between groups.
Usage
trans_beta$cal_group_distance( within_group = TRUE, by_group = NULL, ordered_group = NULL, sep = " vs " )
Arguments
within_groupdefault TRUE; whether obtain distance table of paired samples within groups; if FALSE, obtain distances of paired samples between any two groups.
by_groupdefault NULL; one colname name of
sample_tableinmicrotableobject. If provided, transform distances by the providedby_groupparameter. This is especially useful for ordering and filtering values further. Whenwithin_group = TRUE, the result of by_group parameter is the format of paired groups. Whenwithin_group = FALSE, the result of by_group parameter is the format same with the group information insample_table.ordered_groupdefault NULL; a vector representing the ordered elements of
groupparameter; only useful when within_group = FALSE.sepdefault TRUE; a character string to separate the group names after merging them into a new name.
Returns
res_group_distance stored in object.
Examples
\donttest{
t1$cal_group_distance(within_group = TRUE)
}
Method cal_group_distance_diff()
Differential test of converted distances across groups.
Usage
trans_beta$cal_group_distance_diff( group = NULL, by_group = NULL, by_ID = NULL, ... )
Arguments
groupdefault NULL; a column name of
object$res_group_distanceused for the statistics; If NULL, use thegroupinside the object.by_groupdefault NULL; a column of
object$res_group_distanceused to perform the differential test among elements ingroupparameter for each element inby_groupparameter. Soby_grouphas a larger scale thangroupparameter. Thisby_groupis very different from theby_groupparameter in thecal_group_distancefunction.by_IDdefault NULL; a column of
object$res_group_distanceused to perform paired t test or paired wilcox test for the paired data, such as the data of plant compartments for different plant species (ID). Soby_IDshould be the smallest unit of sample collection without any repetition in it....parameters passed to
cal_difffunction oftrans_alphaclass.
Returns
res_group_distance_diff stored in object.
Examples
\donttest{
t1$cal_group_distance_diff()
}
Method plot_group_distance()
Plot the distances of paired groups within or between groups.
Usage
trans_beta$plot_group_distance(plot_group_order = NULL, ...)
Arguments
plot_group_orderdefault NULL; a vector used to order the groups in the plot.
...parameters (except measure) passed to
plot_alphafunction oftrans_alphaclass.
Returns
ggplot.
Examples
\donttest{
t1$plot_group_distance()
}
Method plot_clustering()
Plot clustering result based on the ggdendro package.
Usage
trans_beta$plot_clustering( color_values = RColorBrewer::brewer.pal(8, "Dark2"), measure = NULL, group = NULL, replace_name = NULL )
Arguments
color_valuesdefault RColorBrewer::brewer.pal(8, "Dark2"); color palette for the text.
measuredefault NULL; beta diversity index; If NULL, using the measure when creating object
groupdefault NULL; if provided, use this group to assign color.
replace_namedefault NULL; if provided, use this as label.
Returns
ggplot.
Examples
t1$plot_clustering(group = "Group", replace_name = c("Saline", "Type"))
Method clone()
The objects of this class are cloneable with this method.
Usage
trans_beta$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
Examples
## ------------------------------------------------
## Method `trans_beta$new`
## ------------------------------------------------
data(dataset)
t1 <- trans_beta$new(dataset = dataset, measure = "bray", group = "Group")
## ------------------------------------------------
## Method `trans_beta$cal_ordination`
## ------------------------------------------------
t1$cal_ordination(method = "PCoA")
## ------------------------------------------------
## Method `trans_beta$plot_ordination`
## ------------------------------------------------
t1$plot_ordination(plot_type = "point")
t1$plot_ordination(plot_color = "Group", plot_shape = "Group", plot_type = "point")
t1$plot_ordination(plot_color = "Group", plot_type = c("point", "ellipse"))
t1$plot_ordination(plot_color = "Group", plot_type = c("point", "centroid"),
centroid_segment_linetype = 1)
## ------------------------------------------------
## Method `trans_beta$cal_manova`
## ------------------------------------------------
t1$cal_manova(manova_all = TRUE)
## ------------------------------------------------
## Method `trans_beta$cal_anosim`
## ------------------------------------------------
t1$cal_anosim()
## ------------------------------------------------
## Method `trans_beta$cal_betadisper`
## ------------------------------------------------
t1$cal_betadisper()
## ------------------------------------------------
## Method `trans_beta$cal_group_distance`
## ------------------------------------------------
t1$cal_group_distance(within_group = TRUE)
## ------------------------------------------------
## Method `trans_beta$cal_group_distance_diff`
## ------------------------------------------------
t1$cal_group_distance_diff()
## ------------------------------------------------
## Method `trans_beta$plot_group_distance`
## ------------------------------------------------
t1$plot_group_distance()
## ------------------------------------------------
## Method `trans_beta$plot_clustering`
## ------------------------------------------------
t1$plot_clustering(group = "Group", replace_name = c("Saline", "Type"))