我正在尝试将一些按两个变量排序的数据可视化:年份和学生。这是我的数据:
graphos <- data.frame(c(2007,2007,2007,2008,2008,2008,2009,2009,2009),
c("A","B","C","A","E","B","D","B","A"),
c(52080,49426,42522,53124,50784,45920,55971,52216,49850))
names(graphos) <- c("Year","Classroom","Students")
graph2 <- ggplot(graphos, aes(fill=Classroom, y=Students, x=Year)) +
geom_bar(position="dodge", stat="identity", color='black')
graph2
结果如下:
我尝试了fill=reorder
的选项,但它也不起作用:
graph2 <- ggplot(graphos, aes(fill=reorder(Classroom, -Students), y=Students, x=Year)) +
geom_bar(position="dodge", stat="identity", color='black')
graph2
我需要的是按年份(升序)和学生(降序)排序,但我的图表只按年份排序。你能救我吗?
谢谢!