How to reorder the sample correctly for bar plot using ggplot2

Hi everyone,

I am using ggplot2 with basic knowledge, so sorry for my question if looks like silly

I have microbiome data and want the samples No. ordered in the bar plot correctly form 1 to 33 (samples No.),
the following command was used
ggplot(mdata_class, aes(x = reorder(Sample, Sample.ID), y = Abundance, fill = Class)) + (time~.) +
geom_bar(stat = "identity") +
scale_fill_manual(values = class_colors) +
breaks = map$Sample.ID,
labels = map$Sample.ID,
drop = FALSE
) + theme(axis.title.x = element_blank(),

however, the resulted bar plot looks like

any advices to reorder the samples number ?
thank you in advance

Sample should be a factor variable. Reorder that way.

1 Like