This class is a wrapper for a series of operations associated with environmental measurements, including redundancy analysis, mantel test and correlation analysis based on An et al. (2019) <doi:10.1016/j.geoderma.2018.09.035>.
new()
trans_env$new( dataset = NULL, env_cols = NULL, add_data = NULL, character2numeric = TRUE, complete_na = FALSE )
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.
env_data in trans_env object.
data(dataset) data(env_data_16S) t1 <- trans_env$new(dataset = dataset, add_data = env_data_16S)
cal_rda()
Redundancy analysis (RDA) based on the rda function in vegan package.
trans_env$cal_rda( use_dbrda = TRUE, add_matrix = NULL, use_measure = NULL, feature_sel = FALSE, taxa_level = NULL, taxa_filter_thres = NULL )
use_dbrda
default TRUE; whether use db-RDA, if FALSE, use RDA.
add_matrix
default NULL; additional distance matrix provided, if you do not want to use the beta diversity matrix within the dataset.
use_measure
default NULL; name of beta diversity matrix. If necessary and not provided, use the first beta diversity matrix.
feature_sel
default FALSE; whether perform the feature selection.
taxa_level
default NULL; If use RDA, provide the taxonomic rank.
taxa_filter_thres
default NULL; If want to filter taxa, provide the relative abundance threshold.
res_rda, res_rda_R2, res_rda_terms and res_rda_axis in object.
\donttest{ t1$cal_rda(use_dbrda = TRUE, use_measure = "bray") }
cal_rda_envsquare()
Fits each environmental vector onto the RDA ordination to obtain the contribution of each variable.
trans_env$cal_rda_envsquare(...)
...
the parameters passing to vegan::envfit function.
res_rda_envsquare in object.
\donttest{ t1$cal_rda_envsquare() }
trans_rda()
transform RDA result for the following plotting.
trans_env$trans_rda( show_taxa = 10, adjust_arrow_length = FALSE, min_perc_env = 1, max_perc_env = 100, min_perc_tax = 1, max_perc_tax = 100 )
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 1; minimum scale value for env arrow, relatively.
max_perc_env
default 100; maximum scale value for env arrow, relatively.
min_perc_tax
default 1; minimum scale value for tax arrow, relatively.
max_perc_tax
default 100; maximum scale value for tax arrow, relatively.
res_rda_trans in object.
\donttest{ t1$trans_rda(adjust_arrow_length = TRUE, max_perc_env = 10) }
plot_rda()
plot RDA result.
trans_env$plot_rda( 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_type = "italic" )
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_type
default "italic"; taxa text style; better to use "italic" for Genus, use "normal" for others.
ggplot object.
\donttest{ t1$plot_rda(plot_color = "Group") }
cal_mantel()
Mantel test between beta diversity matrix and environmental data.
trans_env$cal_mantel( select_env_data = NULL, partial_mantel = FALSE, add_matrix = NULL, use_measure = NULL, method = "pearson", ... )
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
.
res_mantel in object.
\donttest{ t1$cal_mantel(use_measure = "bray") }
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.
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 )
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.
res_cor in object.
\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]) }
plot_cor()
Plot correlation heatmap.
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, plot_x_size = 9, mylabels_x = NULL, font_family = NULL, ... )
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 heatmap with clustering plot.
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.
plot_x_size
default 9; x axis text size.
mylabels_x
default NULL; provide x axis text labels additionally; only available when pheatmap = TRUE.
font_family
default NULL; font family used in ggplot2; only available when pheatmap = FALSE.
...
paremeters pass to ggplot2::geom_tile or pheatmap, depending on the pheatmap = FALSE or TRUE.
plot.
\donttest{ t1$plot_cor(pheatmap = FALSE) }
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.
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, ... )
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.
plot.
\donttest{ t1$plot_scatterfit(x = 1, y = 2, alpha = .5) }
print()
Print the trans_env object.
trans_env$print()
clone()
The objects of this class are cloneable with this method.
trans_env$clone(deep = FALSE)
deep
Whether to make a deep clone.
# NOT RUN {
## ------------------------------------------------
## Method `trans_env$new`
## ------------------------------------------------
data(dataset)
data(env_data_16S)
t1 <- trans_env$new(dataset = dataset, add_data = env_data_16S)
## ------------------------------------------------
## Method `trans_env$cal_rda`
## ------------------------------------------------
# }
# NOT RUN {
t1$cal_rda(use_dbrda = TRUE, use_measure = "bray")
# }
# NOT RUN {
## ------------------------------------------------
## Method `trans_env$cal_rda_envsquare`
## ------------------------------------------------
# }
# NOT RUN {
t1$cal_rda_envsquare()
# }
# NOT RUN {
## ------------------------------------------------
## Method `trans_env$trans_rda`
## ------------------------------------------------
# }
# NOT RUN {
t1$trans_rda(adjust_arrow_length = TRUE, max_perc_env = 10)
# }
# NOT RUN {
## ------------------------------------------------
## Method `trans_env$plot_rda`
## ------------------------------------------------
# }
# NOT RUN {
t1$plot_rda(plot_color = "Group")
# }
# NOT RUN {
## ------------------------------------------------
## Method `trans_env$cal_mantel`
## ------------------------------------------------
# }
# NOT RUN {
t1$cal_mantel(use_measure = "bray")
# }
# NOT RUN {
## ------------------------------------------------
## Method `trans_env$cal_cor`
## ------------------------------------------------
# }
# NOT RUN {
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])
# }
# NOT RUN {
## ------------------------------------------------
## Method `trans_env$plot_cor`
## ------------------------------------------------
# }
# NOT RUN {
t1$plot_cor(pheatmap = FALSE)
# }
# NOT RUN {
## ------------------------------------------------
## Method `trans_env$plot_scatterfit`
## ------------------------------------------------
# }
# NOT RUN {
t1$plot_scatterfit(x = 1, y = 2, alpha = .5)
# }
Run the code above in your browser using DataLab