trans_abund object for taxonomic abundance visualization.This class is a wrapper for the taxonomic abundance transformations and visualization (e.g., bar plot, boxplot, heatmap, pie chart and line chart).
The converted data style is the long-format for ggplot2 plot.
new()trans_abund$new(
dataset = NULL,
taxrank = "Phylum",
show = 0,
ntaxa = 10,
groupmean = NULL,
group_morestats = FALSE,
delete_taxonomy_lineage = TRUE,
delete_taxonomy_prefix = TRUE,
prefix = NULL,
use_percentage = TRUE,
input_taxaname = NULL,
high_level = NULL,
high_level_fix_nsub = NULL
)datasetdefault NULL; the object of microtable class.
taxrankdefault "Phylum"; taxonomic level, i.e. a column name in tax_table of the input object.
The function extracts the abundance from the taxa_abund list according to the names in the list.
If the taxa_abund list is NULL, the function can automatically calculate the relative abundance to generate taxa_abund list.
showdefault 0; the mean relative abundance threshold for filtering the taxa with low abundance.
ntaxadefault 10; how many taxa are selected to use. Taxa are ordered by abundance from high to low.
This parameter does not conflict with the parameter show. Both can be used. ntaxa = NULL means the parameter will be invalid.
groupmeandefault NULL; calculate mean abundance for each group. Select a column name in microtable$sample_table.
group_morestatsdefault FALSE; only available when groupmean parameter is provided;
Whether output more statistics for each group, including min, max, median and quantile;
Thereinto, quantile25 and quantile75 denote 25% and 75% quantiles, respectively.
delete_taxonomy_lineagedefault TRUE; whether delete the taxonomy lineage in front of the target level.
delete_taxonomy_prefixdefault TRUE; whether delete the prefix of taxonomy, such as "g__".
prefixdefault NULL; character string; available when delete_taxonomy_prefix = T;
default NULL represents using the "letter+__", e.g. "k__" for Phylum level;
Please provide the customized prefix when it is not standard, otherwise the program can not correctly recognize it.
use_percentagedefault TRUE; show the abundance percentage.
input_taxanamedefault NULL; character vector; input taxa names to select some taxa.
high_leveldefault NULL; a taxonomic rank, such as "Phylum", used to add the taxonomic information of higher level. It is required for the legend with nested taxonomic levels in the bar plot or the higher taxonomic level in facets of y axis in the heatmap.
high_level_fix_nsubdefault NULL; an integer, used to fix the number of selected abundant taxa in each taxon from higher taxonomic level.
If the total number under one taxon of higher level is less than the high_level_fix_nsub, the total number will be used.
When high_level_fix_nsub is provided, the taxa number of higher level is calculated as: ceiling(ntaxa/high_level_fix_nsub).
Note that ntaxa means either the parameter ntaxa or the taxonomic number obtained by filtering according to the show parameter.
data_abund stored in the object. The column 'all_mean_abund' represents mean relative abundance across all the samples.
So the values in one taxon are all same across all the samples.
If the sum of column 'Abundance' in one sample is larger than 1, the 'Abundance', 'SD' and 'SE' has been multiplied by 100.
\donttest{
data(dataset)
t1 <- trans_abund$new(dataset = dataset, taxrank = "Phylum", ntaxa = 10)
}
plot_bar()Bar plot.
trans_abund$plot_bar(
color_values = RColorBrewer::brewer.pal(8, "Dark2"),
bar_full = TRUE,
bar_type = deprecated(),
others_color = "grey90",
facet = NULL,
order_x = NULL,
x_axis_name = NULL,
barwidth = NULL,
use_alluvium = FALSE,
clustering = FALSE,
clustering_plot = FALSE,
cluster_plot_width = 0.2,
facet_color = "grey95",
strip_text = 11,
legend_text_italic = FALSE,
xtext_angle = 0,
xtext_size = 10,
xtext_keep = TRUE,
xtitle_keep = TRUE,
ytitle_size = 17,
coord_flip = FALSE,
ggnested = FALSE,
high_level_add_other = FALSE
)color_valuesdefault RColorBrewer::brewer.pal(8, "Dark2"); colors palette for the bars.
bar_fulldefault TRUE; Whether the bar shows all the features (including 'Others').
Default TRUE means total abundance are summed to 1 or 100 (percentage). FALSE means 'Others' will not be shown.
bar_typedeprecated. Please use bar_full argument instead.
others_colordefault "grey90"; the color for "Others" taxa.
facetdefault NULL; a character vector for the facet; group column name of sample_table, such as, "Group";
If multiple facets are needed, please provide ordered names, such as c("Group", "Type").
The latter should have a finer scale than the former one;
Please adjust the facet orders in the plot by assigning factors in sample_table before creating trans_abund object or
assigning factors in the data_abund table of trans_abund object.
When multiple facets are used, please first install package ggh4x using the command install.packages("ggh4x").
order_xdefault NULL; vector; used to order the sample names in x axis; must be the samples vector, such as c("S1", "S3", "S2").
x_axis_nameNULL; a character string; a column name of sample_table in dataset; used to show the sample names in x axis.
barwidthdefault NULL; bar width, see width in geom_bar.
use_alluviumdefault FALSE; whether add alluvium plot. If TRUE, please first install ggalluvial package.
clusteringdefault FALSE; whether order samples by the clustering.
clustering_plotdefault FALSE; whether add clustering plot.
If clustering_plot = TRUE, clustering will be also TRUE in any case for the clustering.
cluster_plot_widthdefault 0.2, the dendrogram plot width; available when clustering_plot = TRUE.
facet_colordefault "grey95"; facet background color.
strip_textdefault 11; facet text size.
legend_text_italicdefault FALSE; whether use italic in legend.
xtext_angledefault 0; number ranging from 0 to 90; used to adjust x axis text angle to reduce text overlap;
xtext_sizedefault 10; x axis text size.
xtext_keepdefault TRUE; whether retain x text.
xtitle_keepdefault TRUE; whether retain x title.
ytitle_sizedefault 17; y axis title size.
coord_flipdefault FALSE; whether flip cartesian coordinates so that horizontal becomes vertical, and vertical becomes horizontal.
ggnesteddefault FALSE; whether use nested legend. Need ggnested package to be installed (https://github.com/gmteunisse/ggnested).
To make it available, please assign high_level parameter when creating the object.
high_level_add_otherdefault FALSE; whether add 'Others' (all the unknown taxa) in each taxon of higher taxonomic level.
Only available when ggnested = TRUE.
ggplot2 object.
\donttest{
t1$plot_bar(facet = "Group", xtext_keep = FALSE)
}
plot_heatmap()Plot the heatmap.
trans_abund$plot_heatmap(
color_values = rev(RColorBrewer::brewer.pal(n = 11, name = "RdYlBu")),
facet = NULL,
facet_switch = "y",
x_axis_name = NULL,
order_x = NULL,
withmargin = TRUE,
plot_numbers = FALSE,
plot_text_size = 4,
plot_breaks = NULL,
margincolor = "white",
plot_colorscale = "log10",
min_abundance = 0.01,
max_abundance = NULL,
strip_text = 11,
xtext_keep = TRUE,
xtext_angle = 0,
xtext_size = 10,
ytext_size = 11,
xtitle_keep = TRUE,
grid_clean = TRUE,
legend_title = "% Relative\nAbundance",
pheatmap = FALSE,
...
)color_valuesdefault rev(RColorBrewer::brewer.pal(n = 11, name = "RdYlBu")); colors palette for the plotting.
facetdefault NULL; a character vector for the facet; a group column name of sample_table, such as, "Group";
If multiple facets are needed, please provide ordered names, such as c("Group", "Type").
The latter should have a finer scale than the former one;
Please adjust the facet orders in the plot by assigning factors in sample_table before creating trans_abund object or
assigning factors in the data_abund table of trans_abund object.
When multiple facets are used, please first install package ggh4x using the command install.packages("ggh4x").
facet_switchdefault "y"; By default, the labels in facets are displayed on the top and right of the plot.
If "x", the top labels will be displayed to the bottom. If "y", the right-hand side labels will be displayed to the left. Can also be set to "both".
When the high_level is found in the object, the function will generate facets for the higher taxonomy in y axis.
So the default "y" of the parameter is to make the visualization better when high_level is found.
This parameter will be passed to the switch parameter in ggplot2::facet_grid or ggh4x::facet_nested function.
x_axis_nameNULL; a character string; a column name of sample_table used to show the sample names in x axis.
order_xdefault NULL; vector; used to order the sample names in x axis; must be the samples vector, such as, c("S1", "S3", "S2").
withmargindefault TRUE; whether retain the tile margin.
plot_numbersdefault FALSE; whether plot the number in heatmap.
plot_text_sizedefault 4; If plot_numbers TRUE, text size in plot.
plot_breaksdefault NULL; The legend breaks.
margincolordefault "white"; If withmargin TRUE, use this as the margin color.
plot_colorscaledefault "log10"; color scale.
min_abundancedefault .01; the minimum abundance percentage in plot.
max_abundancedefault NULL; the maximum abundance percentage in plot, NULL reprensent the max percentage.
strip_textdefault 11; facet text size.
xtext_keepdefault TRUE; whether retain x text.
xtext_angledefault 0; number ranging from 0 to 90; used to adjust x axis text angle to reduce text overlap;
xtext_sizedefault 10; x axis text size.
ytext_sizedefault 11; y axis text size.
xtitle_keepdefault TRUE; whether retain x title.
grid_cleandefault TRUE; whether remove grid lines.
legend_titledefault "% Relative\nAbundance"; legend title text.
pheatmapdefault FALSE; whether use pheatmap package to plot the heatmap.
...paremeters pass to pheatmap when pheatmap = TRUE.
ggplot2 object or grid object based on pheatmap.
\donttest{
t1 <- trans_abund$new(dataset = dataset, taxrank = "Genus", ntaxa = 40)
t1$plot_heatmap(facet = "Group", xtext_keep = FALSE, withmargin = FALSE)
}
plot_box()Box plot.
trans_abund$plot_box(
color_values = RColorBrewer::brewer.pal(8, "Dark2"),
group = NULL,
show_point = FALSE,
point_color = "black",
point_size = 3,
point_alpha = 0.3,
plot_flip = FALSE,
boxfill = TRUE,
middlecolor = "grey95",
middlesize = 1,
xtext_angle = 0,
xtext_size = 10,
ytitle_size = 17,
...
)color_valuesdefault RColorBrewer::brewer.pal(8, "Dark2"); colors palette for the box.
groupdefault NULL; a column name of sample table to show abundance across groups.
show_pointdefault FALSE; whether show points in plot.
point_colordefault "black"; If show_point TRUE; use the color
point_sizedefault 3; If show_point TRUE; use the size
point_alphadefault .3; If show_point TRUE; use the transparency.
plot_flipdefault FALSE; Whether rotate plot.
boxfilldefault TRUE; Whether fill the box with colors.
middlecolordefault "grey95"; The middle line color.
middlesizedefault 1; The middle line size.
xtext_angledefault 0; number ranging from 0 to 90; used to adjust x axis text angle to reduce text overlap;
xtext_sizedefault 10; x axis text size.
ytitle_sizedefault 17; y axis title size.
...parameters pass to geom_boxplot function.
ggplot2 object.
\donttest{
t1$plot_box(group = "Group")
}
plot_line()Plot the line chart.
trans_abund$plot_line(
color_values = RColorBrewer::brewer.pal(8, "Dark2"),
plot_SE = TRUE,
position = position_dodge(0.1),
errorbar_size = 1,
errorbar_width = 0.1,
point_size = 3,
point_alpha = 0.8,
line_size = 0.8,
line_alpha = 0.8,
line_type = 1,
xtext_angle = 0,
xtext_size = 10,
ytitle_size = 17
)color_valuesdefault RColorBrewer::brewer.pal(8, "Dark2"); colors palette for the points and lines.
plot_SEdefault TRUE; TRUE: the errorbar is \(mean±se\); FALSE: the errorbar is \(mean±sd\).
positiondefault position_dodge(0.1); Position adjustment, either as a string (such as "identity"), or the result of a call to a position adjustment function.
errorbar_sizedefault 1; errorbar line size.
errorbar_widthdefault 0.1; errorbar width.
point_sizedefault 3; point size for taxa.
point_alphadefault 0.8; point transparency.
line_sizedefault 0.8; line size.
line_alphadefault 0.8; line transparency.
line_typedefault 1; an integer; line type.
xtext_angledefault 0; number ranging from 0 to 90; used to adjust x axis text angle to reduce text overlap;
xtext_sizedefault 10; x axis text size.
ytitle_sizedefault 17; y axis title size.
ggplot2 object.
\donttest{
t1 <- trans_abund$new(dataset = dataset, taxrank = "Genus", ntaxa = 5)
t1$plot_line(point_size = 3)
t1 <- trans_abund$new(dataset = dataset, taxrank = "Genus", ntaxa = 5, groupmean = "Group")
t1$plot_line(point_size = 5, errorbar_size = 1, xtext_angle = 30)
}
plot_pie()Pie chart.
trans_abund$plot_pie(
color_values = RColorBrewer::brewer.pal(8, "Dark2"),
facet_nrow = 1,
strip_text = 11,
add_label = FALSE,
legend_text_italic = FALSE
)color_valuesdefault RColorBrewer::brewer.pal(8, "Dark2"); colors palette for each section.
facet_nrowdefault 1; how many rows in the plot.
strip_textdefault 11; sample title size.
add_labeldefault FALSE; Whether add the percentage label in each section of pie chart.
legend_text_italicdefault FALSE; whether use italic in legend.
ggplot2 object.
\donttest{
t1 <- trans_abund$new(dataset = dataset, taxrank = "Phylum", ntaxa = 6, groupmean = "Group")
t1$plot_pie(facet_nrow = 1)
}
plot_donut()Donut chart based on the ggpubr::ggdonutchart function.
trans_abund$plot_donut(
color_values = RColorBrewer::brewer.pal(8, "Dark2"),
label = TRUE,
facet_nrow = 1,
legend_text_italic = FALSE,
...
)color_valuesdefault RColorBrewer::brewer.pal(8, "Dark2"); colors palette for the donut.
labeldefault TRUE; whether show the percentage label.
facet_nrowdefault 1; how many rows in the plot.
legend_text_italicdefault FALSE; whether use italic in legend.
...parameters passed to ggpubr::ggdonutchart.
combined ggplot2 objects list, generated by ggpubr::ggarrange function.
\dontrun{
t1 <- trans_abund$new(dataset = dataset, taxrank = "Phylum", ntaxa = 6, groupmean = "Group")
t1$plot_donut(label = TRUE)
}
plot_radar()Radar chart based on the ggradar package (https://github.com/ricardo-bion/ggradar).
trans_abund$plot_radar(
color_values = RColorBrewer::brewer.pal(8, "Dark2"),
...
)color_valuesdefault RColorBrewer::brewer.pal(8, "Dark2"); colors palette for samples.
...parameters passed to ggradar::ggradar function except group.colours parameter.
ggplot2 object.
\dontrun{
t1 <- trans_abund$new(dataset = dataset, taxrank = "Phylum", ntaxa = 6, groupmean = "Group")
t1$plot_radar()
}
plot_tern()Ternary diagrams based on the ggtern package.
trans_abund$plot_tern(
color_values = RColorBrewer::brewer.pal(8, "Dark2"),
color_legend_guide_size = 4
)color_valuesdefault RColorBrewer::brewer.pal(8, "Dark2"); colors palette for the samples.
color_legend_guide_sizedefault 4; The size of legend guide for color.
ggplot2 object.
\dontrun{
t1 <- trans_abund$new(dataset = dataset, taxrank = "Phylum", ntaxa = 6, groupmean = "Group")
t1$plot_tern()
}
clone()The objects of this class are cloneable with this method.
trans_abund$clone(deep = FALSE)deepWhether to make a deep clone.
## ------------------------------------------------
## Method `trans_abund$new`
## ------------------------------------------------
# \donttest{
data(dataset)
t1 <- trans_abund$new(dataset = dataset, taxrank = "Phylum", ntaxa = 10)
# }
## ------------------------------------------------
## Method `trans_abund$plot_bar`
## ------------------------------------------------
# \donttest{
t1$plot_bar(facet = "Group", xtext_keep = FALSE)
# }
## ------------------------------------------------
## Method `trans_abund$plot_heatmap`
## ------------------------------------------------
# \donttest{
t1 <- trans_abund$new(dataset = dataset, taxrank = "Genus", ntaxa = 40)
t1$plot_heatmap(facet = "Group", xtext_keep = FALSE, withmargin = FALSE)
# }
## ------------------------------------------------
## Method `trans_abund$plot_box`
## ------------------------------------------------
# \donttest{
t1$plot_box(group = "Group")
# }
## ------------------------------------------------
## Method `trans_abund$plot_line`
## ------------------------------------------------
# \donttest{
t1 <- trans_abund$new(dataset = dataset, taxrank = "Genus", ntaxa = 5)
t1$plot_line(point_size = 3)
t1 <- trans_abund$new(dataset = dataset, taxrank = "Genus", ntaxa = 5, groupmean = "Group")
t1$plot_line(point_size = 5, errorbar_size = 1, xtext_angle = 30)
# }
## ------------------------------------------------
## Method `trans_abund$plot_pie`
## ------------------------------------------------
# \donttest{
t1 <- trans_abund$new(dataset = dataset, taxrank = "Phylum", ntaxa = 6, groupmean = "Group")
t1$plot_pie(facet_nrow = 1)
# }
## ------------------------------------------------
## Method `trans_abund$plot_donut`
## ------------------------------------------------
if (FALSE) {
t1 <- trans_abund$new(dataset = dataset, taxrank = "Phylum", ntaxa = 6, groupmean = "Group")
t1$plot_donut(label = TRUE)
}
## ------------------------------------------------
## Method `trans_abund$plot_radar`
## ------------------------------------------------
if (FALSE) {
t1 <- trans_abund$new(dataset = dataset, taxrank = "Phylum", ntaxa = 6, groupmean = "Group")
t1$plot_radar()
}
## ------------------------------------------------
## Method `trans_abund$plot_tern`
## ------------------------------------------------
if (FALSE) {
t1 <- trans_abund$new(dataset = dataset, taxrank = "Phylum", ntaxa = 6, groupmean = "Group")
t1$plot_tern()
}
Run the code above in your browser using DataLab