add_metadata()
adds sample or taxon metadata to the sample or taxon
table, respectively, of a tidytacos object.
Arguments
- ta
A tidytacos object.
- metadata
A tibble containing data for each sample or taxon. Samples/taxa should be rows, while metadata variables should be columns. At least one column name needs to be shared with the sample or taxa table of the tidytacos object. The default shared column name is 'sample' for samples and 'taxon' for taxa.
- table_type
The type of table to add, either 'sample' or 'taxa'.
Value
A tidytacos object with the metadata added.
A tidytacos object with metadata columns added to the taxa or sample table.
See also
Other sample-modifiers:
add_alpha()
,
add_alphas()
,
add_ord()
,
add_sample_clustered()
,
add_spike_ratio()
,
add_total_absolute_abundance()
,
add_total_count()
,
add_total_density()
,
cluster_samples()
Examples
# Initiate counts matrix
x <- matrix(
c(1500, 1300, 280, 356),
ncol = 2
)
rownames(x) <- c("taxon1", "taxon2")
colnames(x) <- c("sample1", "sample2")
# Convert to tidytacos object
data <- create_tidytacos(x,
taxa_are_columns = FALSE
)
# Initiate sample tibble
sample <- c("sample1", "sample2")
environment <- c("food fermentation", "human stool")
sample_tibble <- tibble::tibble(sample, environment)
# Add sample tibble to tidytacos object
data <- data %>%
add_metadata(sample_tibble)
#> Joining with `by = join_by(sample)`
# Initiate taxon tibble
genera <- c("Lactobacillus", "Limosilactobacillus")
species <- c("crispatus", "reuteri")
taxonomy <- tibble::tibble(taxon = rownames(x), genera, species)
# Add taxon tibble to tidytacos object
data <- data %>%
add_metadata(taxonomy, table_type = "taxa")
#> Joining with `by = join_by(taxon)`