我想绘制一个条形图,并根据 年级
和 分数
排序条形。对于我的问题可能听起来有些傻。我知道如何按一个变量排序,但不知道两个变量怎么排序。有人可以教我吗?
df<-structure(list(ID = c("A1-18-603", "A1-19-604", "A2-20-605",
"A1-21-606", "A1-22-607", "A2-16-601", "A5-17-602", "A1-14-502",
"A1-15-503", "A1-13-501", "A5-12-403", "A2-10-401", "A1-11-402",
"A2-07-301", "A5-08-302", "A3-09-303", "A1-06-203", "A1-05-202",
"A3-04-201", "A1-02-102", "A6-03-103", "A1-01-101"), Score = c(33.58,
12.88, 12.65, 12.19, 11.5, 9.66, 3.45, 26.22, 13.11, 11.96, 78.42,
38.64, 16.1, 54.74, 12.88, 9.2, 114.53, 25.76, 22.54, 15.87,
13.11, 6.67), Grade = c("6", "6", "6", "6", "6", "6", "6", "5",
"5", "5", "4", "4", "4", "3", "3", "3", "2", "2", "2", "1", "1",
"1")), row.names = c(NA, -22L), class = "data.frame")
ggplot(data = df) +
geom_bar(aes(y = reorder(ID, desc(Grade)), x = Score, fill = Grade), stat = "identity", width = 0.8)
我可以按等级排序,但不知道如何按分数
进一步排序。