I have a dataset (1000 IDs, 9 classes) similar to this one:
ID Class Value
1 A 0.014
1 B 0.665
1 C 0.321
2 A 0.234
2 B 0.424
2 C 0.342
... ... ...
The Value column are (relative) abundances, i.e. the sum of all classes for one individual equals 1.
I would like to create a ggplot geom_bar plot in R where the x axis is not ordered by IDs but by decreasing class abundance, similar to this one:
In our example, let's say that Class B is the most abundant class across all individuals, followed by Class C and finally Class A, the first bar of the x axis would be for the individual with the highest Class B, the second bar would the individual with the second highest Class B, etc.
This is what I tried:
ggplot(df, aes(x=ID, y=Value, fill=Class)) +
geom_bar(stat="identity") +
xlab("") +
ylab("Relative Abundance\n")

