作者:
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)]