Public methods
Method new()
Usage
trans_env$new(
dataset = NULL,
env_cols = NULL,
add_data = NULL,
character2numeric = TRUE,
complete_na = FALSE
)
Arguments
dataset
the object of microtable
Class.
env_cols
default NULL; a vector to select columns in sample_table, when the environmental data is in sample_table.
Either numeric vector or character vector of colnames.
add_data
default NULL; data.frame format; provide the environmental data frame individually; rownames should be sample names.
character2numeric
default TRUE; whether transform the characters or factors to numeric attributes.
complete_na
default FALSE; Whether fill the NA (missing value) in the environmental data;
If TRUE, the function can run the interpolation with the mice package; Please first install mice package.
Returns
env_data in trans_env object.
Examples
data(dataset)
data(env_data_16S)
t1 <- trans_env$new(dataset = dataset, add_data = env_data_16S)
Method cal_ordination()
Redundancy analysis (RDA) and Correspondence Analysis (CCA) based on the vegan package.
Usage
trans_env$cal_ordination(
method = c("RDA", "dbRDA", "CCA")[1],
feature_sel = FALSE,
taxa_level = NULL,
taxa_filter_thres = NULL,
use_measure = NULL,
add_matrix = NULL,
...
)
Arguments
method
default c("RDA", "dbRDA", "CCA")[1]; the ordination method.
feature_sel
default FALSE; whether perform the feature selection.
taxa_level
default NULL; If use RDA or CCA, provide the taxonomic rank, such as "Phylum" or "Genus";
If use otu_table; please input "OTU".
taxa_filter_thres
default NULL; If want to filter taxa, provide the relative abundance threshold.
use_measure
default NULL; name of beta diversity matrix. If necessary and not provided, use the first beta diversity matrix.
add_matrix
default NULL; additional distance matrix provided, when you do not want to use the beta diversity matrix within the dataset;
only available when method = "dbRDA".
...
paremeters pass to dbrda or rda or cca function according to the input of method.
Returns
res_ordination, res_ordination_R2, res_ordination_terms and res_ordination_axis in object.
Examples
\donttest{
t1$cal_ordination(method = "RDA", use_measure = "bray")
}
Method cal_ordination_envsquare()
Fits each environmental vector onto the ordination to obtain the contribution of each variable.
Usage
trans_env$cal_ordination_envsquare(...)
Arguments
...
the parameters passing to vegan::envfit function.
Returns
res_ordination_envsquare in object.
Examples
\donttest{
t1$cal_ordination_envsquare()
}
Method trans_ordination()
transform ordination result for the following plotting.
Usage
trans_env$trans_ordination(
show_taxa = 10,
adjust_arrow_length = FALSE,
min_perc_env = 0.1,
max_perc_env = 0.8,
min_perc_tax = 0.1,
max_perc_tax = 0.8
)
Arguments
show_taxa
default 10; taxa number shown in the plot.
adjust_arrow_length
default FALSE; whether adjust the arrow length to be clear
min_perc_env
default 0.1; used for scaling up the minimum of env arrow; multiply by the maximum distance between samples and origin.
max_perc_env
default 0.8; used for scaling up the maximum of env arrow; multiply by the maximum distance between samples and origin.
min_perc_tax
default 0.1; used for scaling up the minimum of tax arrow; multiply by the maximum distance between samples and origin.
max_perc_tax
default 0.8; used for scaling up the maximum of tax arrow; multiply by the maximum distance between samples and origin.
Returns
res_ordination_trans in object.
Examples
\donttest{
t1$trans_ordination(adjust_arrow_length = TRUE, max_perc_env = 10)
}
Method plot_ordination()
plot ordination result.
Usage
trans_env$plot_ordination(
plot_color = NULL,
plot_shape = NULL,
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),
taxa_text_color = "firebrick1",
taxa_text_italic = TRUE
)
Arguments
plot_color
default NULL; group used for color.
plot_shape
default NULL; group used for shape.
color_values
default RColorBrewer::brewer.pal(8, "Dark2"); color pallete.
shape_values
default see the function; vector used in the shape, see ggplot2 tutorial.
taxa_text_color
default "firebrick1"; taxa text colors.
taxa_text_italic
default TRUE; "italic"; whether use "italic" style for the taxa text in the plot.
Returns
ggplot object.
Examples
\donttest{
t1$plot_ordination(plot_color = "Group")
}
Method cal_mantel()
Mantel test between beta diversity matrix and environmental data.
Usage
trans_env$cal_mantel(
select_env_data = NULL,
partial_mantel = FALSE,
add_matrix = NULL,
use_measure = NULL,
method = "pearson",
...
)
Arguments
select_env_data
default NULL; numeric or character vector to select columns in env_data; if not provided, automatically select the columns with numeric attributes.
partial_mantel
default FALSE; whether use partial mantel test; If TRUE, use other measurements as the zdis.
add_matrix
default NULL; additional distance matrix provided, if you donot want to use the beta diversity matrix in the dataset.
use_measure
default NULL; name of beta diversity matrix. If necessary and not provided, use the first beta diversity matrix.
method
default "pearson"; one of "pearson", "spearman" and "kendall"; correlation method.
...
paremeters pass to mantel
.
Returns
res_mantel in object.
Examples
\donttest{
t1$cal_mantel(use_measure = "bray")
}
Method cal_cor()
Calculating the correlations between taxa abundance and environmental variables.
Indeed, it can also be used for calculating other correlation between any two variables from two tables.
Usage
trans_env$cal_cor(
use_data = c("Genus", "all", "other")[1],
select_env_data = NULL,
cor_method = c("pearson", "spearman", "kendall")[1],
p_adjust_method = "fdr",
p_adjust_type = c("Type", "Taxa", "Env")[3],
add_abund_table = NULL,
by_group = NULL,
use_taxa_num = NULL,
other_taxa = NULL,
group_use = NULL,
group_select = NULL,
taxa_name_full = TRUE
)
Arguments
use_data
default "Genus"; "Genus", "all" or "other"; "Genus" or other taxonomic name: use genus or other taxonomic abundance table in taxa_abund;
"all": use all merged taxa abundance table; "other": provide additional taxa name with other_taxa parameter which is necessary.
select_env_data
default NULL; numeric or character vector to select columns in env_data; if not provided, automatically select the columns with numeric attributes.
cor_method
default "pearson"; "pearson", "spearman" or "kendall"; correlation method.
p_adjust_method
default "fdr"; p.adjust method.
p_adjust_type
default "Env"; "Type", "Taxa" or "Env"; p.adjust type; Env: environmental data; Taxa: taxa data; Type: group used.
add_abund_table
default NULL; additional data table to be used. Samples must be rows.
by_group
default NULL; one column name or number in sample_table; calculate correlations for different groups separately.
use_taxa_num
default NULL; integer; a number used to select high abundant taxa; only useful when use_data parameter is a taxonomic level, e.g. "Genus".
other_taxa
default NULL; provide additional taxa, see use_data parameter.
group_use
default NULL; numeric or character vector to select one column in sample_table for selecting samples; together with group_select.
group_select
default NULL; the group name used; will retain samples within the group.
taxa_name_full
default TRUE; Whether retain the complete taxonomic name of taxa.
Returns
res_cor in object.
Examples
\donttest{
t2 <- trans_diff$new(dataset = dataset, method = "rf", group = "Group", rf_taxa_level = "Genus")
t1 <- trans_env$new(dataset = dataset, add_data = env_data_16S[, 4:11])
t1$cal_cor(use_data = "other", p_adjust_method = "fdr", other_taxa = t2$res_rf$Taxa[1:40])
}
Method plot_cor()
Plot correlation heatmap.
Usage
trans_env$plot_cor(
color_vector = c("#053061", "white", "#A50026"),
color_palette = NULL,
pheatmap = FALSE,
filter_feature = NULL,
ylab_type_italic = FALSE,
keep_full_name = FALSE,
keep_prefix = TRUE,
text_y_order = NULL,
text_x_order = NULL,
font_family = NULL,
cluster_ggplot = "none",
cluster_height_rows = 0.2,
cluster_height_cols = 0.2,
text_y_position = "right",
fontsize = 9,
mylabels_x = NULL,
...
)
Arguments
color_vector
default c("#053061", "white", "#A50026"); colors with only three values representing low, middle and high value.
color_palette
default NULL; a customized palette with more color values; if provided, use it instead of color_vector.
pheatmap
default FALSE; whether use pheatmap package to plot the heatmap.
filter_feature
default NULL; character vector; used to filter features that only have significance labels in the filter_feature vector.
For example, filter_feature = "" can be used to filter features that only have "", no any "*".
ylab_type_italic
default FALSE; whether use italic type for y lab text.
keep_full_name
default FALSE; whether use the complete taxonomic name.
keep_prefix
default TRUE; whether retain the taxonomic prefix.
text_y_order
default NULL; character vector; provide customized text order for y axis; shown in the plot the top down.
text_x_order
default NULL; character vector; provide customized text order for x axis.
font_family
default NULL; font family used in ggplot2; only available when pheatmap = FALSE.
cluster_ggplot
default "none"; add clustering dendrogram for ggplot2 based heatmap;
available options: "none", "row", "col" or "both". "none": no any clustering used;
"row": add clustering for rows; "col": add clustering for columns; "both": add clustering for both rows and columns.
Only available when pheatmap = FALSE.
cluster_height_rows
default 0.2, the dendrogram plot height for rows; available when cluster_ggplot != "none".
cluster_height_cols
default 0.2, the dendrogram plot height for columns; available cluster_ggplot != "none".
text_y_position
default "right"; "left" or "right"; the y axis text position; ggplot2 based heatmap.
fontsize
default 9; base fontsize for the plot; see fontsize in pheatmap.
mylabels_x
default NULL; provide x axis text labels additionally; only available when pheatmap = TRUE.
...
paremeters pass to ggplot2::geom_tile or pheatmap, depending on the pheatmap = FALSE or TRUE.
Returns
plot.
Examples
\donttest{
t1$plot_cor(pheatmap = FALSE)
}
Method plot_scatterfit()
Scatter plot and add fitted line. The most important thing is to make sure that the input x and y
have correponding sample orders. If one of x and y is a matrix, the other will be also transformed to matrix with Euclidean distance.
Then, both of them are transformed to be vectors. If x or y is a vector with a single value, x or y will be
assigned according to the column selection of the env_data inside.
Usage
trans_env$plot_scatterfit(
x = NULL,
y = NULL,
use_cor = TRUE,
cor_method = "pearson",
add_line = TRUE,
use_se = TRUE,
text_x_pos = NULL,
text_y_pos = NULL,
x_axis_title = "",
y_axis_title = "",
pvalue_trim = 4,
cor_coef_trim = 3,
lm_fir_trim = 2,
lm_sec_trim = 2,
lm_squ_trim = 2,
...
)
Arguments
x
default NULL; a single numeric or character value or a vector or a distance matrix used for the x axis.
If x is a single value, it will be used to select the column of env_data inside.
If x is a distance matrix, it will be transformed to be a vector.
y
default NULL; a single numeric or character value or a vector or a distance matrix used for the y axis.
If y is a single value, it will be used to select the column of env_data inside.
If y is a distance matrix, it will be transformed to be a vector.
use_cor
default TRUE; TRUE for correlation; FALSE for regression.
cor_method
default "pearson"; one of "pearson", "kendall" and "spearman".
add_line
default TRUE; whether add the fitted line in the plot.
use_se
default TRUE; Whether show the confidence interval for the fitting.
text_x_pos
default NULL; the central x axis position of the fitting text.
text_y_pos
default NULL; the central y axis position of the fitting text.
x_axis_title
default ""; the title of x axis.
y_axis_title
default ""; the title of y axis.
pvalue_trim
default 4; trim the decimal places of p value.
cor_coef_trim
default 3; trim the decimal places of correlation coefficient.
lm_fir_trim
default 2; trim the decimal places of regression first coefficient.
lm_sec_trim
default 2; trim the decimal places of regression second coefficient.
lm_squ_trim
default 2; trim the decimal places of regression R square.
...
the parameters passing to ggplot2::geom_point function.
Returns
plot.
Examples
\donttest{
t1$plot_scatterfit(x = 1, y = 2, alpha = .5)
}
Method print()
Print the trans_env object.
Usage
trans_env$print()
Method clone()
The objects of this class are cloneable with this method.
Usage
trans_env$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.