更新一下自己的問題,我想要在ggplot上按照y值總合大小排序我的x類別,以下code
#Data
hp=read.csv(textConnection(
"class,year,amount
a,99,100
a,100,200
a,101,150
b,100,50
b,101,100
c,102,70
c,102,80
c,103,90
c,104,50
d,102,90"))
hp$year=as.factor(hp$year)
#Plotting
p=ggplot(data=hp)
p+geom_bar(binwidth=0.5,stat="identity")+ #
aes(x=reorder(class,amount),y=amount,label=amount,fill=year)+theme()
#↑這邊新加入reorder試圖將amount依照class重排
結果:http://imgur.com/DYsMqwl
#↑發現c,b,d有按照sum(amount)降冪排列,但是a沒有
想請問各位版友有無解決辦法呢?懇請賜教