I have a data.frame like this
OTU DCA1.Score ID
1 Ac1 -0.05377328 Gp01
2 Ac2 2.49918986 Gp02
3 Ac3 0.42897126 Gp04
and another one like this
OTU DCA1.Score ID
1 APB_2 1.151251e+00 APB
2 APB_1 9.556547e-01 APB
3 ACT_8 -2.686852e-01 ACT
4 ACT_3 -5.396745e-01 ACT
5 VMC_1 -1.236140e-02 VMC
6 ACT_15 -3.473628e-01 ACT
7 ACT_1 -2.229005e-01 ACT
In both cases i use ggplot2 for a barchart
library(ggplot2)
ggplot(df, aes(x=OTU,y=DCA1.Score, color=ID)) +
geom_bar(stat="identity") +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1, size=5))
In reality both dataframes have 340 rows. The first df features 21 factors in the ID column, the second one just 13.
ggplot will sort the second dataframe by factor "ID" before plotting, the first one is left untouched. Why is that?