I have a dataframe consisting of a number of different subjects, and the percentages of grades obtained in each of them. I can produce a percentage chart with:
ggplot(data=marks,aes(fill=Grades,y=Percentage,x=Subject)) + geom_bar(position="fill",stat="identity")
However, the letter grades I'm using include HD (High Distinction), D (Distinction), C (Credit), P (Pass), N (Fail) and a few others for withdrawn, ungraded pass etc. The plot command automatically orders them alphabetically: C, D, HD, N, P ... whereas I want them in order of highest grade to lowest: HD, D, C, P, N, ...
How can I include that order in my ggplot function call?
Note, if it helps, the first few rows of the dataframe are:
Grades Subject Percentage
1 HD Math 24.16
2 D Math 35.91
3 C Math 24.16
4 P Math 11.41
5 N Math 4.03
6 WD-LATE Math 0.00
and so on: one row for every subject and grade.