Hi,
Making taxa barplot in R does not require converting .qza files to .qzv files. I'm not sure which step you were stuck on. Below is an example using metadata, feature table and taxonomy file from the "Moving Picture" tutorial.
> # Load packages
> library(tidyverse)
> library(RColorBrewer)
> library(cowplot)
> library(qiime2R)
> library(MicrobeR)
>
> # Load function
> source("make_taxa_barplot.R")
>
> # Import data ##################################################################
> # Metadata
> metadata <- read_tsv("metadata.tsv", comment = "#q2")
>
> metadata <- metadata %>%
> rename_at(vars(contains("-")), ~gsub("-", "_", .x)) %>% # replace dash with underscore
> rename(SampleID = "sample_id") # use "SampleID" as sample identifier
>
> # Feature table
> table <- read_qza("table.qza")
>
> count_tab <- table$data %>% as.data.frame()
>
> # Taxonomy
> taxonomy <- read_qza("taxonomy.qza")
>
> tax_tab <- taxonomy$data %>%
> as.data.frame() %>%
> separate(Taxon, sep = ";", c("Kingdom", "Phylum", "Class", "Order", "Family", "Genus", "Species")) %>%
> column_to_rownames("Feature.ID") %>%
> select(-Confidence)
>
> # Taxa barplot #################################################################
> # Phylum-level -----------------------------------------------------------------
> # Collapse feature table at phylum level
> tab_phy <- Summarize.Taxa(count_tab, tax_tab)$Phylum %>%
> # the following 4 lines of code prune the taxonomy to contain phylum names only
> rownames_to_column("tax") %>%
> filter(!grepl("NA", tax)) %>% # remove taxa without kingdom or phylum level annotation
> mutate(tax = gsub("\\[|\\]", "", tax), # remove square brackets
> tax = gsub("k__.*p__", "", tax)) %>%
> column_to_rownames("tax")
>
> # Plot taxa on individual basis
> make_taxa_barplot(table = tab_phy,
> metadata = metadata,
> group_by = body_site,
> ntaxa = 10, # number of taxa to display
> nrow = 1, # nrow for facetting
> plot_mean = FALSE, # plot mean relative abundance within each group
> cluster_sample = FALSE, # cluster samples based on similarity
> sample_label = SampleID,
> italize_taxa_name = TRUE)
>
> ggsave("taxa_barplot_moving_picture_individual.png")
> # Plot taxa using group means
> make_taxa_barplot(table = tab_phy,
> metadata = metadata,
> group_by = body_site,
> ntaxa = 10,
> nrow = 1,
> plot_mean = TRUE,
> cluster_sample = FALSE,
> sample_label = body_site,
> italize_taxa_name = TRUE)
>
> ggsave("taxa_barplot_moving_picture_mean.png")
You can download the demo files and play with the code. You may need to modify the code to make it work for your project. demo.zip (235.8 KB)