I have a data frame, df:
District TypeofSchool Nstudents Nteachers Percent_failure
1 A I 1936 157 21.5
2 A II 67 8 0.5
3 A III 5288 146 78.0
4 B I 653 72 27.8
5 B II 865 22 9.0
6 B III 2278 100 63.2
对于使用ggplot2进行图形绘制,我想要重新记录地区因素。我想按该地区的学生与教师比例对其进行排序,即汇总该地区所有类型学校的学生和教师人数并计算比率;通过该比率重新排列地区,以便在绘制堆积条形图时,最低比例地区将显示在最左侧位置:
ggplot(df, aes(x=District, y=Percent_failure, fill=TypeofSchool)) +
geom_bar(stat="identity")
有什么建议如何重新排序?