Order of sample in taxa barplots


I'm using qiime2r to plot the taxa barplots using this command:

taxa_barplot(Summarize.Taxa(ASVs$data, as.data.frame(tax_table))$Phylum, metadata, "Treatment") 

How can I set the order of my samples in the resulting graph? C10 C11 C12 are plotted before C7 C8 C9, and I want the correct order (7 8 9 10 11 12)

Thanks for the help

Try changing sample name to C07, C08, etc, if possible.

Thanks, but i can't change the names.....are there any options to set the sample orders with a function?

You can set the order of sample names in the x-axis by converting the sample id column into a factor. Assuming that your sample id column name is "sample_id", you can:

metadata$sample_id <- factor(
   levels = c("C1GEN", ... , "C7R", ..., "C12VR") # my desired sample order 

I'm following this qiime2R tutorial, so i can't figure out how to reorder the samples as you've suggested