trans_env {microeco} | R Documentation |
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, 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.
add_data
default NULL; provide the environmental data frame individually.
complete_na
default FALSE; Whether fill the NA in the environmental data.
env_data and dataset 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 in object.
t1$cal_rda(use_dbrda = TRUE, use_measure = "bray")
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.
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 c("pearson", "spearman", "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: genus abundance, all: all taxa, other: provide additional taxa name with other_taxa parameter.
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_corr()
Plot correlation heatmap.
trans_env$plot_corr( color_vector = c("#00008B", "#102D9B", "#215AAC", "#3288BD", "#66C2A5", "#E6F598", "#FFFFBF", "#FED690", "#FDAE61", "#F46D43", "#D53E4F"), pheatmap = FALSE, ylab_type_italic = FALSE, keep_full_name = FALSE, keep_prefix = TRUE, plot_x_size = 9, mylabels_x = NULL, font_family = NULL )
color_vector
color pallete.
pheatmap
default FALSE; whether use heatmap with clustering plot.
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.
plot.
\donttest{ t1$plot_corr(pheatmap = FALSE) }
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.
## ------------------------------------------------ ## 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` ## ------------------------------------------------ t1$cal_rda(use_dbrda = TRUE, use_measure = "bray") ## ------------------------------------------------ ## Method `trans_env$trans_rda` ## ------------------------------------------------ t1$trans_rda(adjust_arrow_length = TRUE, max_perc_env = 10) ## ------------------------------------------------ ## Method `trans_env$plot_rda` ## ------------------------------------------------ t1$plot_rda(plot_color = "Group") ## ------------------------------------------------ ## Method `trans_env$cal_mantel` ## ------------------------------------------------ t1$cal_mantel(use_measure = "bray") ## ------------------------------------------------ ## Method `trans_env$cal_cor` ## ------------------------------------------------ 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 `trans_env$plot_corr` ## ------------------------------------------------ t1$plot_corr(pheatmap = FALSE)