楼主:
ardodo (米蟲)
2015-06-03 01:18:59各位板友好,我的问题是,如何将ggplot绘制的堆叠长条图,以堆叠的y值总合排序
附图说明:
http://imgur.com/bwv8fRn
我想要把这张图的x类别以y总合降幂排列,也就是变成a,c,b,d的顺序
请问该怎么做呢?
以下为我画出此图的指令,求解
levels(hp$class) = c("a", "c", "b", "d")不想要手动改可以用 order 跟 tapplyhp$class[order(tapply(hp$amount, hp$class, sum),decreasing = FALSE)]levels(hp$class) = hp$class[order(tapply(hp$amount, hp$class, sum), decreasing = FALSE)]