# Order of sample in taxa barplots

**URL:** <https://forum.qiime2.org/t/order-of-sample-in-taxa-barplots/22391>\
**Category:** Other Bioinformatics Tools\
**Tags:** qiime2r\
**Created:** [March 5, 2022, 4:49pm UTC](https://forum.qiime2.org/t/order-of-sample-in-taxa-barplots/22391 "2022-03-05T16:49:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![AndreaC](https://forum.qiime2.org/user_avatar/forum.qiime2.org/andreac/32/11910_2.png) [@AndreaC](https://forum.qiime2.org/u/AndreaC)\
**Post date:** [March 5, 2022, 4:49pm UTC](https://forum.qiime2.org/t/order-of-sample-in-taxa-barplots/22391/1 "2022-03-05T16:49:39Z")

</div>

Hello,

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

```auto
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

---

<div class="post-metadata">

**Author:** ![kindergarten](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/k/b38774/32.png) [@kindergarten](https://forum.qiime2.org/u/kindergarten)\
**Post date:** [March 5, 2022, 5:48pm UTC](https://forum.qiime2.org/t/order-of-sample-in-taxa-barplots/22391/2 "2022-03-05T17:48:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![AndreaC](https://forum.qiime2.org/user_avatar/forum.qiime2.org/andreac/32/11910_2.png) [@AndreaC](https://forum.qiime2.org/u/AndreaC)\
**Post date:** [March 5, 2022, 6:05pm UTC](https://forum.qiime2.org/t/order-of-sample-in-taxa-barplots/22391/3 "2022-03-05T18:05:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![yanxianl](https://forum.qiime2.org/user_avatar/forum.qiime2.org/yanxianl/32/2039_2.png) [@yanxianl](https://forum.qiime2.org/u/yanxianl)\
**Post date:** [March 6, 2022, 5:47pm UTC](https://forum.qiime2.org/t/order-of-sample-in-taxa-barplots/22391/4 "2022-03-06T17:47:01Z")

</div>

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:

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

```

---

<div class="post-metadata">

**Author:** ![AndreaC](https://forum.qiime2.org/user_avatar/forum.qiime2.org/andreac/32/11910_2.png) [@AndreaC](https://forum.qiime2.org/u/AndreaC)\
**Post date:** [March 9, 2022, 5:42pm UTC](https://forum.qiime2.org/t/order-of-sample-in-taxa-barplots/22391/5 "2022-03-09T17:42:54Z")

</div>

> **[Microbiome analysis in R - March 2023](https://uw-madison-microbiome-hub.github.io/Microbiome_analysis_in-_R/)**
>
> Sailendharan Sudakaran

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