df$x<-factor(df$x,levels=c("B","A","D","C","E"))## 绘制条形图ggplot(data=df,aes(x=x,y=y))+geom_bar(stat="identity") 如图所示,X轴标签的顺序被调整过来啦!